Reputation: 163
How do I close the following popup when its content is clicked?
<Button Name="myButton" Content="Hover to open" />
<Popup PlacementTarget="{Binding ElementName=myButton}" Placement="Bottom">
<Popup.Resources>
<DataConversion:BooleanOrConverter x:Key="booleanOrConverter" />
</Popup.Resources>
<Popup.IsOpen>
<MultiBinding Mode="OneWay" Converter="{StaticResource booleanOrConverter}">
<Binding Mode="OneWay" ElementName="myButton" Path="IsMouseOver"/>
<Binding RelativeSource="{RelativeSource Self}" Path="IsMouseOver" />
</MultiBinding>
</Popup.IsOpen>
<!-- some content here -->
</Popup>
I wanted to avoid writing code in the code behind file and binding visual and behavioral things like IsOpen property or MouseDown event to the ViewModel.
Upvotes: 3
Views: 6007
Reputation: 21713
You need an EventTrigger
on your Popup
that triggers a storyboard that contains a BooleanAnimationUsingKeyFrames
that sets IsOpen
to false
, similar to this. Easier to just use code-behind ;o)
Upvotes: 2
Reputation: 184516
You could just make the Popup.Child
a Button
(style it to not look like one), handle its Click
event and set IsOpen
to false
(preferably using SetCurrentValue
to not destroy the binding).
You can either do this in code behind or using a behavior/trigger action.
Upvotes: 2