I am trying to define a style for menu items so when the mouse is over the main menu item, the next level of sub menu items will automatically open. So I created a style for MenuItem and made a trigger for 'IsMouseover' to cause 'IsSubmenuOpen' to become 'true'. It works fine once, but after clicking on a sub menu item, let it close, then next time the mouse is over the main menu, the sub menu items no longer opens automatically.
I looked at the MenuItem control template and see the 'IsSubmenuOpen' is bounded via TemplateBinding, so I would hope my style that sets this should override every time.
I am using VS 2012 with .Net Framework 4.5.
The XAML follows. Notice the 'tool tips menu item':
<Menu Height="28"
Margin="10, 3, 0, 0"
KeyboardNavigation.TabNavigation="Cycle"
Background="{StaticResource Background1Key}"
Foreground="{StaticResource Foreground1Key}" >
<Menu.ItemsPanel>
<ItemsPanelTemplate>
<Grid VerticalAlignment="Center"/>
</ItemsPanelTemplate>
</Menu.ItemsPanel>
<MenuItem Name="ViewMenu"
Style="{StaticResource MainMenuItem}"
Header="_View">
<MenuItem Name="ToolTipsMenuItem"
Style="{StaticResource ToolTipsMenuItem}"/>
</MenuItem>
</Menu>
The styles are:
<!-- For tool tips on/off menu item -->
<Style x:Key="ToolTipsMenuItem" TargetType="{x:Type MenuItem}" BasedOn="{StaticResource SubMenuItem}">
<Setter Property="Header" Value="_Show ToolTips"/>
<Setter Property="IsCheckable" Value="True"/>
<Setter Property="IsChecked" Value="{Binding Source={x:Static p:Settings.Default},
Path=ShowToolTips, Mode=TwoWay}"/>
</Style>
<Style x:Key="SubMenuItem" TargetType="{x:Type MenuItem}">
<Setter Property="Background" Value="{StaticResource Background2Key}"/>
<Setter Property="Foreground" Value="{StaticResource Foreground2Key}"/>
</Style>
<Style x:Key="MainMenuItem" TargetType="{x:Type MenuItem}" >
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{StaticResource Foreground1Key}"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="IsSubmenuOpen" Value="True"/>
<Setter Property="Cursor" Value="Hand"/>
</Trigger>
</Style.Triggers>
</Style>
So the first time the mouse is over the main menu, the tool tip sub menu item opens, but only once. If I click on the tooltip menu item to change it, it changes and closes. But now the mouse over the main menu won't auto open the sub menu tool tip item.
Also, I hear a faint chuckling. I think the system is laughing at me!
Thanks for any help!
philb222