Problems with Popup

This one’s a bit odd. I’d built A UserControl which contained another UserControl inside a Popup control, as I wanted the second control to appear like a tooltip, but with specific positioning. That all worked fine when it was just appearing on the page, but I also wanted to have a nice ‘fade in’ effect, so I added a couple of storyboards, but when the control was created in the popup, the storyboard complained that it couldn’t resolve names of elements in the Xaml. I’m not sure quite why this was, but I assume it’s due to the way that the Popup is deferring the adding of the child and its elements to the visual tree until it’s made visible. But whatever the reason, it’s a pain.

So I had to build the storyboard in code in the constructor, and that all seemed to work properly. I triggered the fade in animation in the Loaded event handler so it gets triggered when the control is added to the visual tree. The fade out was less of a problem since that was always called when the control was fully built. I had to add an event to the control so that the calling control could be informed when the fade out had completed, so that it could set the popup IsOpen flag to false after the animation had finished.

But I still can’t help thinking I’m missing the ‘correct’ way to do this. There’s not much documentation about how Popup actually works, certainly none that I can find which discusses anything more complex than a static control.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s