0

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
Lundin
  • 195,001
  • 40
  • 254
  • 396
Selva
  • 1,310
  • 2
  • 14
  • 31
  • So you want multiple items that you click to be `checked`? – WPF-it Jun 24 '13 at 08:09
  • @WPF-it ,No,not like that, If i `Checked` one item ,all other items must be `Unchecked` – Selva Jun 24 '13 at 08:52
  • Then what is happening in your case? – WPF-it Jun 24 '13 at 09:26
  • If i execute the above code `ShowAll` Menuitem will be **Checked** by default, now when i click `Firstpage`, `ShowAll` menuitem gets **Unchecked**,this is correct, but `FirstPage` **MenuItem** is not getting Checked. I couldn figure out the solution – Selva Jun 24 '13 at 09:42

0 Answers0