Silverlight 5–What’s New #2

April 13, 2011

This is a second post in series of posts about new features in Silverlight 5.

This post focuses at simple, yet much desired feature of multiple windows support.

First – some clarification: multiple windows will work in elevated out-of-browser mode only.

To demonstrate this feature I’ve built simplest application which spans 5 additional windows on button click.

The “child” window presents a UserControl. Child window content:

<UserControl x:Class="MultipleWindows_OOB.ChildWindowContent"
    d:DesignHeight="300" d:DesignWidth="400">
    <Grid x:Name="LayoutRoot" Background="LightGoldenrodYellow">
        <TextBlock HorizontalAlignment="Center" TextAlignment="Center" 
                   FontFamily="Courier New" FontSize="22">
            <Run Text="This is a secondary window"/>
            <Run Text="#"/>
            <Run Text="{Binding WindowNumber}"/>

The “WindowNumber” defined as Dependency Property in code behind as follows:

private int windowNumber;
public int WindowNumber 
    get { return windowNumber; }
        windowNumber = value;

        if (null != PropertyChanged)
            PropertyChanged(this, new PropertyChangedEventArgs("WindowNumber"));

public event PropertyChangedEventHandler PropertyChanged;

Now to the interesting part – spawning a new windows:

if (App.Current.IsRunningOutOfBrowser && App.Current.HasElevatedPermissions)
    for (int i = 0; i < 5; i++)
        Window wnd = new Window();
        wnd.Width = 640;
        wnd.Height = 480;
        wnd.Left = 25 + i * 20;
        wnd.Top = 30 + i * 30;
        wnd.WindowState = WindowState.Normal;
        wnd.WindowStyle = WindowStyle.SingleBorderWindow;
        wnd.Title = "Child Window #" + (i + 1);
        wnd.Content = new ChildWindowContent() { WindowNumber = (i + 1) };
        wnd.Visibility = System.Windows.Visibility.Visible;
    MessageBox.Show("This works only in Elevated OOB mode!");

Pretty simple, ah? At running application looks like the follows:


Note: closing the main window will close all the child windows.

The sample located here.


Stay tuned for more to come soon.


Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


one comment

  1. Tory Burch OutletSeptember 7, 2011 ב 10:46

    thanks for your sharing,I like it!