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.
You need an
EventTriggeron yourPopupthat triggers a storyboard that contains aBooleanAnimationUsingKeyFramesthat setsIsOpentofalse, similar to this. Easier to just use code-behind ;o)