tags:

views:

133

answers:

1

Hi all

When I create a Silverlight project in the Visual Studio, then build it, the VS would popup a page with the silverlight that I just made.But that silverlight object always on the left-up corner, is there any way to make it in the horizontal center of the page?

Best Regards,

+1  A: 

Ordinarily the positioning of the plugin content within the rest of the HTML page is a problem for the HTML/CSS to solve not the Silverlight. (If you want that look for CSS solutions that center any HTML element in the Viewport and then apply it to the object tag in the .aspx or .htm hosting your control).

However I'm going to guess you don't have any other content in the page, the page exists only to host the silverlight content. In this case it may be better to let the Silverlight content occupy the entire page. The default .aspx and .htm test pages are designed to allow the plugin to do that, you just need to move the Width and Height properties from the UserControl to the inner "LayoutRoot" element and set the "LayoutRoot" to have "Center" HorizontalAlignment and VerticalAlignment.

In other words from this:-

<UserControl xmlns=".... blah...."
  Width="600" Height="400">
  <Grid x:Name="LayoutRoot">
    <!-- Content here --?
  </Grid>
</UserControl>

to this:-

<UserControl xmlns=".... blah....">
  <Grid x:Name="LayoutRoot" Width="600" Height="400"
    HorizontalAlignment="Center" VerticalAlignment="Center">
    <!-- Content here --?
  </Grid>
</UserControl>
AnthonyWJones
Thanks, this is exactly what I need.
Yongwei Xing