Popup.StaysOpen in Silverlight14 Jul 2010
Continuing 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:
Popupin question must be closed when you set the
StaysOpenproperty. If, for example, your
Popupis already open when your application first starts, events won’t hook up correctly.
Popup’s parent is used to determine whether the user has clicked outside the bounds of the
Popup, and therefore whether the
Popupshould be closed. So you should host the
Popupas 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.