destro
Well-known member
- Joined
- Mar 28, 2020
- Messages
- 46
- Programming Experience
- 1-3
My Menu is perfectly bound with observable collection in view model and all submenu items fires click event properly using below xaml, but I am unable to set the same click event for first menu items. Is it possible to set same click event on all primary menu items?
This is my menuClickEvent in UserControl.xaml.cs:
UserControl.xaml:
<Menu Background="Lavender" x:Name="Styled2" Margin="162,-46,146,335" Grid.ColumnSpan="2">
<MenuItem ItemsSource="{Binding LaalKitabYears}" Height="21" Width="124" HorizontalContentAlignment="Center" Padding="0">
<MenuItem.Header>
<Label VerticalContentAlignment="Top" Margin="0,0,-120,0" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" Padding="0" Content="{Binding LaalKitabYears[0].year}"/>
</MenuItem.Header>
<MenuItem.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}">
<Setter Property="Header" Value="{Binding Path=year}"/>
<Setter Property="ItemsSource" Value="{Binding subMenuItems}"/>
<EventSetter Event="Click" Handler="MenuItem_Click"/>
<Setter Property="Background" Value="LavenderBlush"/>
</Style>
</MenuItem.ItemContainerStyle>
</MenuItem>
</Menu>
This is my menuClickEvent in UserControl.xaml.cs:
UserControl.xaml.cs:
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show((e.OriginalSource as MenuItem).Header.ToString());
}