I have a window with Button and ListBox.
<Window x:Class="ListBoxFail.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="350" Width="525"> <Grid> <Popup Name="Popup" StaysOpen="False"> <Rectangle Fill="Blue" Width="100" Height="100"/> </Popup> <Button Content="ClickMe" Click="OpenPopup" VerticalAlignment="Top"/> <ListBox SelectionChanged="OpenPopup" VerticalAlignment="Bottom"> <ListBoxItem Content="One"/> <ListBoxItem Content="Two"/> </ListBox> </Grid> </Window>
The button and ListBox launch a popup window:
namespace ListBoxFail { partial class MainWindow { public MainWindow() { InitializeComponent(); } private void OpenPopup(object a, object b) { Popup.IsOpen = true; } } }
When you click the button, a popup window opens. Clicking elsewhere closes the popup as expected.
When you click in the ListBox, a popup window opens. However, the only way to close the popup at this point is to make the main window lose focus. Clicking on a window or pressing a button does not close the pop-up window.
What gives? Why does the ListBox ignore the StaysOpen = false directive? What am I doing wrong?
source share