Introduction
In Silverlight 3, you can use a Popup
control to show a non-modal window containing any sort of content. Although you can control the Popup
's position by setting the HorizontalOffset
and VerticalOffset
properties, it can sometimes be hard to predict where the user would like the window to be positioned. Unfortunately, the user has no way to move the Popup
control.
By attaching a PopupDragDrop
object to your Popup
control, you allow the user to drag it around the Silverlight window and place it wherever she likes.
Using the code
Simply call the static PopupDragDrop.Attach
method to wire up an instance of the class to your Popup
. Attach
takes two arguments: the Popup
control and the FrameworkElement
that will be the Popup
's child (which holds the actual content that will be displayed). For example:
Popup myPopup = new Popup { HorizontalOffset = 200, VerticalOffset = 300 };
PopupDragDrop.Attach(myPopup, new myUserControl());
From this point, you show/hide the Popup
in the usual way, using the IsOpen
property of the Popup
and the Visibility
property of the child.
History
- 11/19/2009 - Initial contribution.