Popup.StaysOpen in Silverlight
14 Jul 2010Continuing on with the theme of restoring some WPF goodness to Silverlight, here is an attached behavior that gives Silverlight’s Popup
control a handy StaysOpen
property. It builds on top of the placement behavior I presented in my last post, so I’ve just supplemented the demo I did for that post. Call me lazy.
Usage looks like this:
<Popup b:Popup.StaysOpen="False">
<TextBlock>Popup contents</TextBlock>
</Popup>
The only limitations I know of are:
- The
Popup
in question must be closed when you set theStaysOpen
property. If, for example, yourPopup
is already open when your application first starts, events won’t hook up correctly. - The
Popup
’s parent is used to determine whether the user has clicked outside the bounds of thePopup
, and therefore whether thePopup
should be closed. So you should host thePopup
as far up in your visual tree as appropriate, or you could add another dependency property with which you can explicitly specify the parent. I haven’t needed the latter idea yet, so haven’t bothered to add it – maybe I’ll need it later.
Enjoy!