I have a control that is using a popup with some WPF controls inside of it, and StaysOpen="True". The problem is when clicking on the popup when the application doesn't have focus, the application does not receive focus. I've done a bit of research, and it seems like this may be due to the fact that popups are meant to be used for menus, so they don't have all of the proper windows message handlers hooked up. Here is a barebones sample to demoing the problem:
<Window x:Class="TestWindowPopupBehavior.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:TestWindowPopupBehavior="clr-namespace:TestWindowPopupBehavior" Title="MainWindow" Height="350" Width="525">
<Grid>
<Popup StaysOpen="True" IsOpen="True" Placement="Center">
<ListBox>
<TextBlock>123</TextBlock>
<TextBlock>123</TextBlock>
<TextBlock>123</TextBlock>
<TextBlock>123</TextBlock>
<TextBlock>123</TextBlock>
<TextBlock>123</TextBlock>
</ListBox>
</Popup>
</Grid>
</Window>
What I would expect to happen in step 4 would be the application would receive focus, and the listbox would select the new item.
Are there any workarounds to this problem, or something obvious I'm missing? I'm looking at rewriting the whole popup code with full-fledged windows, and re-implementing the behavior we have, but that seems really complicated just to fix a small problem like this.
If you handle MouseLeftButtonDown
event, you can call Window.Activate()
method. but you should write it for each element - Popup
and for all TextBlock
s.
The problem you can met with is that on Windows you can swap mouse buttons, where left became right and vice versa (but I don't know how this works), so, may be you have to handle MouseRightButtonDown
event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With