Auto Max Resize Silverlight Page In Web Browser

Published on Monday, August 22, 2011

How to fill the entire browser window using Silverlight page ?

Very easy! When you create a new Silverlight application, There are Height and Width properties for the UserControl, but by default these 2 properties are not set. If these 2 properties are not set, the Silverlight will occupy entire web browser page. Just like the following code demo:

(Note: DesignHeight and DesignWidth are only for design, they are not Height and Width)

<UserControl x:Class="SLDataBind.MainPage"
    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"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">
    </Grid>
</UserControl>

If you want to limit the width and height, just add Height and Width properties:

<UserControl x:Class="SLDataBind.MainPage"
    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"
    d:DesignHeight="300" d:DesignWidth="400" "Height="300" Width="400">

    <Grid x:Name="LayoutRoot" Background="White">
    </Grid>
</UserControl>