0

I have a simple window with a menu containing items bound to view models.

    <DockPanel>
    <Menu DockPanel.Dock="Top" ItemsSource="{Binding ViewModels}">
        <Menu.ItemTemplate>
            <DataTemplate>
                <MenuItem Header="{Binding HeaderName}" Visibility="{Binding MenuVisibility}"
                          Command="{Binding DataContext.ChangeViewCommand, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
                          CommandParameter="{Binding }"/>
            </DataTemplate>
        </Menu.ItemTemplate>
    </Menu>
    <Viewbox Stretch="Fill">
        <ContentControl Content="{Binding CurrentViewModel}"/>
    </Viewbox>
</DockPanel>

Everything for the Menu's style is default plane jane. Nothing fancy. No modifications.

I'm noticing some odd hover behavior when testing the UI. If I mouse over one of the menu items and it becomes highlighted, it seems to 'trap' focus on that item even if the mouse leaves.

So lets says I'm mousing UP through my application, my mouse cursor passes over the menu, highlighting an item. My mouse never stops and attempts to click the Window bar to move the UI to another monitor, the click never lands on the menu bar. I have to click twice, once to remove focus from the menu item, and again to select and drag the window. This also prevents clicks on the minimize, maximize and close buttons as well, or any focus back inside the form. It seems that the MenuItem does not properly notice the mouse has left.

Any ideas? I've tried gutting the Menu and MenuItem styles and have had no success. I've changed the DataTemplate to contain a Grid and used Interactions to trigger the commands, but its ugly and seems hacky.

JordanTDN
  • 181
  • 1
  • 12
  • You can add a trigger to the menu item via style: MouseOver=false -> HasFocus=false – Felix D. Mar 29 '16 at 13:34
  • I do believe 'IsFocused' is a private setter. That won't work. – JordanTDN Mar 29 '16 at 14:00
  • [For someone who see it later](https://stackoverflow.com/questions/46604306/how-to-get-mouseevents-for-a-control-even-if-another-control-already-captured-th) – Mona04_ Apr 02 '22 at 07:53

0 Answers0