I want the menu work like this: when I click on any of the items in the Menu
, it gets checked. Now when I select another item from the same Menu
, the previously selected item becomes unchecked and the newly selected item appears as checked.
<DockPanel.Resources>
<Style TargetType="{x:Type MenuItem}">
<EventSetter Event="Click" Handler="Onfilter_Click" />
</Style>
</DockPanel.Resources>
<Menu DockPanel.Dock="Top" >
<MenuItem x:Name="filtermenu" Header="_FilterType" BorderBrush="White" >
<MenuItem Header="ShowAll" IsChecked="True" />
<MenuItem Header="FirstPage" />
<MenuItem Header="Secondpage" InputGestureText="Alt+F3" />
</MenuItem>
</Menu>
In the code above, I have handled how to Check and Uncheck the items. If I execute the below method, everything gets unchecked.
And also if I press Alt+F3, the Secondpage MenuItem has to be handled, even though if it gets handled, the Onfilter_Click method will get called. How can I achieve this?
Private Sub Onfilter_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Dim b As MenuItem = TryCast(sender, MenuItem)
If Not obj Is Nothing Then
For i As Integer = 0 To filtermenu.Items.Count - 1
Dim mni As System.Windows.Controls.MenuItem = DirectCast(filtermenu.Items(i), System.Windows.Controls.MenuItem)
Dim s As String = mni.Header
If Not s = b.Header Then
If mni.IsChecked Then
mni.IsChecked = False
End If
Else
If Not mni.IsChecked Then
mni.IsChecked = True
End If
End If
Next
' b.IsChecked = True
obj.FilterImages(b.Header)
End If
End Sub