views:

39

answers:

1

How can I set a layout to have 100% width and 100% height?

I want my Silverlight application to stretch in the browser to fill all space.

I am using Expression Blend 4.

Here is my XAML:

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="RichardKnopNew.MainPage"
    Width="960" Height="540">

    <Grid x:Name="LayoutRoot" Width="960" Height="540">
        <Grid.Background>
            <ImageBrush Stretch="Fill" ImageSource="/bg.jpg"/>
        </Grid.Background>
        <Rectangle Fill="#FF252525" Stroke="Black" Opacity="0.7" RadiusX="10" RadiusY="10" Margin="25,115,335,25" StrokeThickness="0" Height="400"/>
    </Grid>
</UserControl>
+2  A: 

Your application should do this automatically. The only reasons why it would not do so are:

  • You've constrained the size of the Silverlight object in the HTML page that hosts the application, or

  • You've explicitly set the width/height of the MainPage object in MainPage.xaml.

Setting the Background property of the MainPage object to a non-white colour should demonstrate this. If not, please include more details (including the XAML you are using).

Hope this helps...

Chris

Chris Anderson
Hi, I have added XAML.
Richard Knop
First, take the Width/Height properties out of your LayoutRoot grid - they aren't needed (the grid will expand to fill the user control). Then, remove the Width/Height properties in your user control (this is what is constraining your UI). For design-time purposes where you want your view to have fixed dimensions so you can actually see the contents of your view (and won't affect the view at run-time), use the d:DesignWidth and d:DesignHeight attached properties like so (note the additional namespace prefix declarations):
Chris Anderson
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d x:Class="RichardKnopNew.MainPage" d:DesignWidth="960" d:DesignHeight="540">
Chris Anderson