Phillip Trelford's Array

POKE 36879,255

Silverlight 5’s ChildWindow in Multiple Windows

A ChildWindow in Silverlight is a control that can be displayed over a parent window blocking its interaction. Silverlight 5 introduces multiple window support for Out-of-Browser (OOB) applications with elevated trust. Unfortunately the ChildWindow control is not currently multi-window aware which means, as is, a child window may only appear in the main window.

Finding the code

With the release of Silverlight 5 the ChildWindow control is part of the main distribution, where previously in Silverlight 4 it was bundled with the Silverlight Toolkit. Therefore to change the code to make the control multi-window aware we’ll have to resort to the Silverlight 4 Toolkit source, conveniently available on CodePlex.

Examining the code

The ChildWindow class makes 2 assumptions that prove false for multi-window apps:

a) the parent control will always be the current application’s RootVisual, e.g.

private static Control RootVisual
{
    get { return Application.Current.RootVisual as Control; }
}

b) the size of the parent window is based on the application’s host window Content, e.g.

Application.Current.Host.Content.Resized += new EventHandler(Page_Resized);

Fixing the code

In terms of code changes, the main one is to allow the parent window of the ChildWindow to be specified using a SetWindow method (as implemented by the Silverlight 5 Popup control). Then to simply replace all references to content made via static properties of the Application class with references to content via the specified window.

To use the updated control we will also need to create a new Silverlight 5 project to host it in and copy the related files over from the Controls project of the Silverlight.Controls.Sdk solution, including the ChildControl’s style from the project’s generic.xaml.

Get it now

The source is available on CodePlex: Silverlight Multi-Window Controls

Comments (1) -

  • Arnaud Weil

    3/1/2012 8:41:18 AM |

    Thanks so much for fixing that bug and making the fix available on CodePlex. You saved my day!

Pingbacks and trackbacks (1)+

Comments are closed