Click here to Skip to main content
11,638,881 members (75,535 online)
Click here to Skip to main content

Draggable Popup Window in Silverlight 3

, 19 Nov 2009 CPOL 27.6K 1.1K 15
Rate this:
Please Sign up or sign in to vote.
Allows a user to drag a popup to any location in the Silverlight window.

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:

// Create the Popup control and set the initial position.	
Popup myPopup = new Popup { HorizontalOffset = 200, VerticalOffset = 300 };

// Attach a PopupDragDrop object to make your Popup draggable.
// The Attach method will also set the Child property of the Popup.
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.

License

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

Share

About the Author

dsmolen
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralWorks a treat Pin
bub19888-Nov-13 4:27
memberbub19888-Nov-13 4:27 
GeneralMy vote of 5 Pin
ricoeur4228-Mar-13 6:37
memberricoeur4228-Mar-13 6:37 
Simple, clean and efficient. thx
GeneralMy vote of 5 Pin
AaronBastian28-Nov-12 2:14
memberAaronBastian28-Nov-12 2:14 
Generalwhat is myUserControl() ? Pin
levashoff27-Apr-11 9:37
memberlevashoff27-Apr-11 9:37 
GeneralRe: what is myUserControl() ? Pin
dsmolen27-Apr-11 11:27
memberdsmolen27-Apr-11 11:27 
GeneralMy vote of 5 Pin
sintesia4-Apr-11 3:22
membersintesia4-Apr-11 3:22 
GeneralCongrats Pin
viv28122-Jan-10 4:44
memberviv28122-Jan-10 4:44 
GeneralRe: Congrats Pin
dsmolen2-Jan-10 7:03
memberdsmolen2-Jan-10 7:03 
GeneralMore Description Needed Pin
Abhijit Jana19-Nov-09 17:15
mvpAbhijit Jana19-Nov-09 17:15 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150728.1 | Last Updated 19 Nov 2009
Article Copyright 2009 by dsmolen
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid