Using a concept found here on StackOverflow. Note that the ToggleButton.IsHitTestVisible
is bound to Popup.IsOpen
, with StaysOpen="False"
. This should mean that touching anywhere outside the Popup
would cause it to close. However...
Touching/Clicking on an ListBoxItem
in the ItemsControl
won't close the Popup
, as is intended. Touching anywhere else within the Popup
does close it. That doesn't seem to add up, according to how this is set up.
<Grid ClipToBounds="True">
<Border Name="Root">
<ToggleButton x:Name="PART_Toggle"
ClickMode="Release"
IsHitTestVisible="{Binding ElementName=PART_Popup,
Path=IsOpen,
Mode=OneWay,
Converter={StaticResource BooleanInverter}}"/>
</Border>
<Popup x:Name="PART_Popup"
IsOpen="{Binding ElementName=PART_Toggle,
Path=IsChecked}"
PlacementTarget="{Binding ElementName=PART_Toggle}"
StaysOpen="False">
<Grid Background="Transparent">
<Grid>
<!-- Anything here (outside of the Item) -->
<ItemsControl>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<!-- Anything in this item template works. The popup does not close -->
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Border>
</Grid>
</Popup>
</Grid>
Any ideas? Thanks.
Edit: Solved
Turns out this was happening because it was inside a custom control which was derived from ListBox
. It didn't seem relevant at the time I made this question, sorry.