Click here to Skip to main content
14,540,070 members

FloatingWindow - Multi-windows Interface for Silverlight 4

Rate this:
4.92 (79 votes)
Please Sign up or sign in to vote.
4.92 (79 votes)
16 May 2011CPOL
Resizable windows simulating multi-windows desktop interface for Silverlight 4

Before you start reading - click on the FloatingWindow demo link to see whether it can be interesting for you. If yes - take it here:

If your browser understands Silverlight 4, you will see something like this:

FloatingWindow demo

Windows in 21 Days

Indeed it required a bit more time to write this library. Though floating windows are common in graphics applications, there are not too many such controls in Silverlight. One of the best is Tim Heuer's FloatableWindow control.

Starting this project, I just wanted to add a few functions to the existing control. But it turned out it was easier to rewrite it completely. Finally, only a few original methods had left after my rework. I added the following functionality:

  • Window can be resized by dragging any edge or a corner
  • Added possibility to snap in moving or resizing window to the nearest window's boundary
  • Window can be minimized, maximized and restore its position and size
  • Window can be opened in modal mode
  • Window can save and restore its size and position
  • Added an icon bar, displaying minimized or all windows
  • The icon bar can display a snapshot of a minimized window or an icon - a FrameworkElement attached to the window.

What's Inside

It would take too much time to explain how it works in details. I am sure, you (like me) don't like reading long boring documents. After all, you have my source code. I'd better describe how it can be used. But before we start, I'll introduce some terms and properties used in the library. The picture below will help me to illustrate them.

FloatingWindow Properties

Where the most important elements are:

  • FloatingWindow - Base class of the resizable windows
  • FloatingWindowHost - Canvas element containing floating windows
  • Iconbar - Panel containing icons of the minimized windows
  • Bootstrap Button - Button opening the Iconbar

Classes and their Members

This section contains a list of the most useful class members.

FloatingWindow Class

  • DialogResult - A value that indicates whether the FloatingWindow was accepted or canceled
  • FlowDirection - The direction that title text flows within window's icon
  • Icon - Content displayed as an icon of the window on the iconbar. If not specified - a snapshot of the window will be displayed as an icon
  • IconText - Text displayed on the icon of the minimized window
  • Position - Current window position
  • ResizeEnabled - A value indicating whether resizing is enabled
  • ResizingAreaThickness - The width of the resizing area
  • ShowInIconbar - A value indicating whether to show minimized window in the iconbar
  • ShowCloseButton - A value indicating whether to show Close button
  • ShowMaximizeButton - A value indicating whether to show Maximize button
  • ShowMinimizeButton - A value indicating whether to show Minimize button
  • Title - Content displayed on the top of the window. Can contain any UI elements
  • TitleBackground - The title background
  • Close - Closes a window
  • RestoreSizeAndPosition - Restores window size and position stored in the IsolatedStorage at the close of the window
  • RestoreWindow - Restores window state, size and its position if it was minimized or maximized
  • Show - Shows a window
  • ShowModal - Shows a window in modal mode
  • Activated - Window is activated and got focus
  • Closed - Window is closed
  • Closing - Window is closing
  • Deactivated - Window is deactivated
  • Maximized - Window is maximized
  • Minimized - Window is minimized
  • Restored - Window is restored

FloatingWindowHost Class

  • IconWidth - The width of the window's icon
  • IconHeight - The height of the window's icon
  • OverlayBrush - The overlay color
  • SnapinEnabled - A value indicating whether snap in is enabled
  • SnapinDistance - Distance between two windows' boundaries when moving window is "attracting" to another one
  • SnapinMargin - A gap between two adjacent windows
  • ShowMinimizedOnlyInIconbar - A value indicating whether to show only minimized windows in the iconbar
  • WindowIconWidth - The width of the iconbar item
  • WindowIconHeight - The height of the iconbar item
  • CloseAllWindows - Closes all floating windows
  • HideIconbar - Hides the iconbar
  • ShowIconbar - Shows the iconbar

Other properties can be found in the code.

Getting Started

The windows are "floating" in the FloatingWindowHost - a Canvas control, which shall be created first, for example, in the markup:

<my:FloatingWindowHost x:Name="host" 

    SnapinEnabled="True" ShowMinimizedOnlyInIconbar="False">

The next step - we shall add our windows to the host:

FloatingWindow window = new FloatingWindow();
window.Title = "New window";

Created window is hidden. The FloatingWindow class has three overloaded methods Show(). The first overload takes no parameters and displays the window in the center of the hosting container. The second and third overloads show the window in the specified coordinates.

There is another option: to restore window size and position saved when the window was closed. Don't worry about saving these parameters. They will be automatically stored in the IsolatedStorage at the close of the window if you specify a unique window's Tag. You can set it during runtime or in the XAML:

<my:FloatingWindow x:Class="FloatingWindowControl.DetailsForm"






    Height="Auto" MinWidth="100" MinHeight="100"

    Title="Details" IconText="Details Form" Tag="Details">

Now you can call the RestoreSizeAndPosition() method to show the window in the previously saved coordinates:


In version 1.2, new ShowModal() method was added to display a floating window in modal mode. It blocks access to underlying windows displaying an overlay above them. The color of the overlay is defined by the OverlayBrush property.

Modal window

Like the ChildWindow it has a DialogResult property, which can be retrieved on windows closing:

FloatingWindow window = new FloatingWindow(); 
window.Title = "Confirmation"; 
window.Closed += (s, a) =>
        bool? result = window.DialogResult;

The major distinction between the modal window and the ChildWindow is that the last one blocks access to the whole area occupied by the Silverlight application, while the floating window in modal mode - only parent FloatingWindowHost.

If you need to know which window becomes active (gets focus), you can subscribe to the Activated or Deactivated events added in the version 1.2.1 (see the MainPage.xaml.cs):

FloatingWindow window = new FloatingWindow();
window.Activated += (s, a) =>
        Debug.WriteLine("Activated: {0}", window.IconText);

Now windows are displayed and we can switch between them, move and resize. Selected window becomes topmost and gets focus. If we want a window to be displayed always above others, we can set its TopMost property to true.

Appearance of the window is defined in the generic.xaml file.

Honey, I Shrunk the Windows

When we move or resize a window, it sticks to the nearest boundaries. Maximal distance at which the window attracts to other windows is 5 pixels and is defined in the SnapinDistance property. If you don't like the windows sticking close to each other, you can specify non-zero SnapinMargin - a gap between adjacent windows. "Mind The Gap" as they say in London.

We can enable or disable resizing setting ResizeEnabled property. Besides, it is possible to disable resizing by one of the coordinates. For example, if we set window's MinWidth equals to its MaxWidth, the window can't be resized by the X coordinate.

Writing code for resizing, I created two interesting (at least for me) by-products: ResizeController and SnapinController. They are more or less independent from other parts of the code and I am going to use them in my other controls.

Dude, Where is my Window?

If we provide a possibility to minimize windows, we shall give quick access to them. And not only to minimized ones because some windows can be moved out of the visible area of the windows container. That's why I recommend to set ShowMinimizedOnlyInIconbar property to false.

The icon bar emerges each time when we press the bootstrap button at the bottom of the windows container and hides when we click on an icon. It contains windows' thumbnails ordered by the IconText. If you don't want to display a window's icon on the icon bar, set its property ShowInIconbar to false.

Window's thumbnail is displayed as a snapshot of the window if the Icon property is not set. Otherwise, the FrameworkElement set by the property will be displayed. For example, look at the markup of the WindowWithChart.xaml:

    <my1:MyIcon />

It defines the MyIcon UserControl as an icon of the window. Nice looking, isn't it? If you want to use an image as an icon, you shall specify its dimensions:

    <Image Source="Images/computer.png" Width="48" Height="48"></Image>

How to Add It to your Project

Here you have a short step-by-step instruction:

  1. Find the in the downloaded archive and copy the ZIP file to the ItemTemplates folder of your Visual Studio. On my machine, it is the "C:\Users\Eugene\Documents\Visual Studio 2010\Templates\ItemTemplates\Visual C#" folder.
  2. Add the SilverFlow.Controls.dll as a reference to your Silverlight project.
  3. Copy the resource dictionary generic.xaml from the SilverFlow.Controls project to your Silverlight project and add it to your application resources.
  4. Right-click on your Silverlight project, select "Add > New Item...", and select the FloatingWindow Control item template.
  5. Build the project.
  6. Add the FloatingWindowHost control to your page, hosting the "floating" windows. See the MainPage.xaml how to do that.
  7. Add a code, creating and displaying the "floating" windows.


First, I would like to thank you all for your contribution, ideas, notes and critique. I do not promise to answer all your letters or implement all your proposals. After all, you are free to use and modify this code.

From time to time, I publish new versions of the FloatingWindow control on my site

If you create something interesting using this library, please write to me, and I'll publish links to your most impressive examples.



  • 24th October, 2010 - Initial version
  • 12th February, 2011 - Version 1.2
    • Fixed a few bugs
    • Reworked the Iconbar
    • Added modal mode
  • 12th May, 2011 - Version 1.2.1
    • Fixed some bugs
    • Added Activated and Deactivated events
    • Added RestoreSizeAndPosition method


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Jevgenij lives in Riga, Latvia. He started his programmer's career in 1983 developing software for radio equipment CAD systems. Created computer graphics for TV. Developed Internet credit card processing systems for banks.
Now he is System Analyst in Accenture.

Comments and Discussions

AnswerRe: Problem in Extensions\GeometryExtensions.cs Pin
Jevgenij Pankov14-Sep-11 9:23
MemberJevgenij Pankov14-Sep-11 9:23 
QuestionThe FloatingWindow Cannot be disposed Pin
Member 799600413-Sep-11 1:44
MemberMember 799600413-Sep-11 1:44 
QuestionMy vote of 5 Pin
Dharmesh_Kemkar7-Sep-11 20:24
MemberDharmesh_Kemkar7-Sep-11 20:24 
AnswerRe: My vote of 5 Pin
Jevgenij Pankov8-Sep-11 7:03
MemberJevgenij Pankov8-Sep-11 7:03 
GeneralRe: My vote of 5 Pin
Dharmesh_Kemkar10-Sep-11 18:14
MemberDharmesh_Kemkar10-Sep-11 18:14 
GeneralRe: My vote of 5 Pin
Jevgenij Pankov10-Sep-11 21:37
MemberJevgenij Pankov10-Sep-11 21:37 
GeneralRe: My vote of 5 Pin
Dharmesh_Kemkar11-Sep-11 12:47
MemberDharmesh_Kemkar11-Sep-11 12:47 
QuestionGreat component! but I got a performance problem Pin
diego mesa tabares17-Aug-11 5:19
Memberdiego mesa tabares17-Aug-11 5:19 
Hello, I have a data grid, my users are typists, they type in the datagrid cells generally two digits numbers, without the floating window the datagrid performance typing data and changing cells was ok, but using your floating window the input is really slow down, the numbers seems to appear too slow in the textbox within the datagrid, and changing cells is too slow.

My suspect is that some of those users who have that issue, they have Pentium 4 2.8 Ghz Processors, with Windows XP and 1 o 2 GB Ram. Some others users with Core i3 Processors don't have such issue. I would like that they update their computers but I can't. Smile | :)

Is possible that floating window penalize that computers? Could you suggest to my some optimization for floating windows?

Thank you some much and nice work!
AnswerRe: Great component! but I got a performance problem Pin
Jevgenij Pankov17-Aug-11 7:00
MemberJevgenij Pankov17-Aug-11 7:00 
SuggestionRe: Great component! but I got a performance problem Pin
joe brockhaus8-Nov-11 10:37
Memberjoe brockhaus8-Nov-11 10:37 
SuggestionSuggestion Pin
Adriaan Davel3-Aug-11 22:04
MemberAdriaan Davel3-Aug-11 22:04 
QuestionVery Nice! Pin
Adriaan Davel3-Aug-11 21:57
MemberAdriaan Davel3-Aug-11 21:57 
QuestionMaximize window on open Pin
Jim Seiwert1-Aug-11 10:24
MemberJim Seiwert1-Aug-11 10:24 
AnswerRe: Maximize window on open Pin
Jevgenij Pankov11-Aug-11 1:41
MemberJevgenij Pankov11-Aug-11 1:41 
QuestionLaunching windows in minimized Pin
nasserbr1-Aug-11 7:35
Membernasserbr1-Aug-11 7:35 
QuestionDrag and drop inside floating window Pin
rosakilo29-Jul-11 3:55
Memberrosakilo29-Jul-11 3:55 
AnswerRe: Drag and drop inside floating window Pin
Jevgenij Pankov29-Jul-11 5:20
MemberJevgenij Pankov29-Jul-11 5:20 
GeneralMy vote of 5 Pin
Dr_armin_R18-Jul-11 4:44
MemberDr_armin_R18-Jul-11 4:44 
GeneralCPU usage Pin
MrPC196917-Jun-11 4:25
MemberMrPC196917-Jun-11 4:25 
GeneralRe: CPU usage Pin
Jevgenij Pankov17-Jun-11 21:54
MemberJevgenij Pankov17-Jun-11 21:54 
GeneralRe: CPU usage Pin
MrPC196919-Jun-11 22:14
MemberMrPC196919-Jun-11 22:14 
GeneralRe: CPU usage Pin
Jevgenij Pankov20-Jun-11 0:16
MemberJevgenij Pankov20-Jun-11 0:16 
GeneralRe: CPU usage Pin
George I. Birbilis5-Aug-13 3:33
MemberGeorge I. Birbilis5-Aug-13 3:33 
GeneralExcellent new version Pin
Member 45654334-Jun-11 23:55
MemberMember 45654334-Jun-11 23:55 
GeneralRe: Excellent new version Pin
Jevgenij Pankov5-Jun-11 5:36
MemberJevgenij Pankov5-Jun-11 5:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 25 Oct 2010


123 bookmarked