views:

175

answers:

1

Hello

I have the following snippet:

<StackPanel>
    <Popup>
        <TextBox ToolTip="Edit current date"/>
    </Popup>
    <Label "Current Date"/>
</StackPanel>

I want the popup to show when the StackPanel is clicked, and hidden when it (the Popup) loses focus.

I was wondering what would be the shortest way to write this in xaml.

+2  A: 

To do this with an animation, use BooleanAnimationUsingKeyFrames. The example shows how to animate the IsEnabled property but will work equally well with Popup.IsOpen. (You'll need to scroll waaaay down to see the XAML example.) Take care about the FillBehavior so that the Popup doesn't animate back to being closed when the animation ends (unless of course this is what you want!).

itowlson
Isn't there a shorter way like BooleanAnimation or BooleanAnimationStoryBoard, I don't want to make the code dirty with unnecessary keyframes and all that...
Shimmy
BooleanAnimationUsingKeyFrames is the only Boolean animation built into the framework. I believe you could derive your own class from BooleanAnimationBase (by overriding GetCurrentValueCore) but haven't tried this. I suspect they omitted a "simple" Boolean animation because animation is normally used only when you want to make changes over time, and a single Boolean change has no time dimension.
itowlson
Shimmy