Search code examples
wpfcomboboxz-order

WPF ComboBox - If expanded, stays on top of all windows


I have a WPF form with ComboBox on it. If I expand my combobox, then open an app such as Notepad or any other, the app will cover my WPF form but the expanded ComboBox portion will still be on top. So it appears as the Notepad app is between the WPF form and its expanded portion of ComboBox (the combo box dropdown). It looks like the ComboBox will show its expanded dropdown always at the top of z-order. This is causing few other issues such as beeing unable to close the WPF form. This is simply wrong.

enter image description here

Above:

  • z-1 is z-order of my WPF form with expanded ComboBox (but note that the expanded area is on top of applications opened and overlapping the WPF form

  • z-2 is order of Notepad application opened and overlapping my WPF form with the ComboBox on it (again, you can see that Notepad overlaps WPF form but the ComboBox expanded dropdown overlaps Notepad. It should be behind Notepad, not in front of it)

  • z-3 is the expanded dropdown of my ComboBox located on WPF form with z-1 order

My ComboBox is part of UserControl and its xaml is like this

    <ComboBox Name="MyComboBox" 
              ItemsSource="{Binding ItemsSet}" 
              DisplayMemberPath="Name"
              SelectedValuePath="Name"
              SelectedItem="{Binding Path=SelectedItem}"
              BorderBrush="Green" 
              BorderThickness="2">
    </ComboBox>

How do I prevent the issue in the provides screenshot?


Solution

  • I "fixed" this by setting the WPF form containing my ComboBox as TopMost="True" in its xaml. Not perfect fix but at least removes the stupid look and all other problems it leads to I discovered. I cannot believe that MS made this default behavior, it is plain stupid.