Sunday, May 15, 2011

Multiple Window Support in Silverlight 5

So much talks about Multiple Window support in Silverlight 5 which made available in beta version around various Silverlight blogs and forums.I am putting my few thoughts here on this feature.

The basic idea behind this feature is host stuff across multiple windows,remember the good old days of MDI forms in Visual Basic 6 days? well its not I will say replica of but its of similar kinds.

The bookish meaning of Multiple Window support is :

The ability to create an application that can have additional top level windows other than the single window that's opened for a Silverlight Out of Browser application

Game starts with namespace System.Windows.Window and it looks like following :

#region Assembly System.Windows.dll, v4.0.30319
// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v5.0\System.Windows.dll

using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Security;

namespace System.Windows
    // Summary:
    //     Represents an out-of-browser application window.
    public sealed class Window : DependencyObject

        //… some code



It’s a sealed class inherited from Dependency Object and as class level xml comment shouts, its an OOB and Work only in Elevated Trust Applications.


You can achieve Multiple Window like this :

Window tearOffWindow = new Window();
//Once a Window has been instantied, one can
//set its initial property values    

tearOffWindow.Height = 300;
tearOffWindow.Width = 400;
tearOffWindow.Top = 24;
tearOffWindow.Left = 30;
tearOffWindow.Title = "Tear Off Stack Panel";
tearOffWindow.Content = mnp.movUIElement; /*Set Content to someFrameworkElement Obj*/;

//Once all the initial properties have
//been set, set the Visibility property
//to 'Visible' to display the Window
tearOffWindow.Visibility = Visibility.Visible;

It will look something like this :


Like this you can create instance of window and put stuff on that whatever you feel appropriate to your application or per requirement. Note that once you close main window another window instance will be closed as well. Its very ideal feature for many Line of Business applications as well. So you should give try to this one today. I know there will be lot more can be done with this,but for the moment I am restricting myself,In upcoming posts I will share more with some demo apps and how you can use this feature at best.

Issues I observed with Multiple Window :

1. Background color/Background property Mystery :

While working I came across that there does not exists any Background property via code which I find strange personally.


2. “Black” Background color :

If you do not set any background color to your UIElement which you are going to tear off,It applies Black color automatically. Some videos and blogs says this is “By default” or “Automatic” but I don’t believe on this,how it can be “by default” since if I don’t apply any background color it should be whitish as usual.This I personally find very strange.


3. Setting WindowStyle as “BorderlessRoundCornersWindow” :

Though it works for parent window well,I will not say this as bug or limitation but if its not expected then they should have thrown compile time error to prompt that it cannot be mixed with Multiple Window support feature but it throws exception here  :


Well, despite of these small issues which I think either might be resolve in coming bits or can be carry ahead ignoring but I feel that I should share this with you so that while designing app based on this Multiple Window feature you will be in good position with possible problems and solution.

I will soon post more deep dive article with some more good examples and features but now my mind is in Hyderabad city where 100+ South Asian MVPs are coming together for Microsoft MVP Open Day 2011 .. I will be traveling there for few days..So see you soon with more good stuff from May end onwards.


No comments: