Silverlight

Unable to set margin on non modal FloatableWindow

Today I was having some problems with the FloatableWindow in my Silverlight project.

What was the problem?
I was already using the control for a while but now I needed to implement a system where you have the possibility to open multiple (non-modal) popups.
Doing this with default settings of the FloatableWindow gave me the problem that all the dialogs where placed on top of each other (like following image).

This is not very useful. So I wanted to create a cascade of dialogs. There is a possibility to set the margin of the dialog with following code:

dialog.Margin = new Thickness(100, 100, 0, 0);

This code works perfectly with the ShowDialog() function for modal dialogs. But when you are creating non-modal dialogs the margin is not working.

Next I will explain what you need to change to get this working.

You can download the source code for the FloatableWindow from CodePlex:
http://floatablewindow.codeplex.com/

Include the project in your Silverlight project.
Open the FloatableWindow.cs file.
Change the ChildWindow_SizeChanged method to the following code:

private void ChildWindow_SizeChanged(object sender, SizeChangedEventArgs e)
{
    if (this.Overlay != null)
    {
        if (e.NewSize.Height != this.Overlay.Height)
        {
            this._desiredContentHeight = e.NewSize.Height;
        }

        if (e.NewSize.Width != this.Overlay.Width)
        {
            this._desiredContentWidth = e.NewSize.Width;
        }
    }

    if (this.IsOpen)
    {
        this.UpdateOverlaySize();
    }
}

From now on the margin setting will also work for non-modal dialogs.



Leave a Reply

Your email address will not be published. Required fields are marked *