Hi.
Based on my forum entry 127366 (https://www.syncfusion.com/forums/127366/binding-and-sub-menuitems) I´m now able to bind menu-items and sub-menu-items to collections in ViewModels or code behind.
I´m now struggling with the problem how to get the event when a sub-menu-item is clicked?
I tried two approaches:
Trigger the tapped event in my DataTemplate:
<UserControl.Resources>
<DataTemplate x:Key="MenuItemInnerTemplate">
<Grid Tag="{Binding}" Tapped="MenuItemTapped">
<TextBlock Text="{Binding Label}"/>
</Grid>
</DataTemplate>
<primitives:HierarchicalDataTemplate ItemsSource="{Binding SubMenuItems}" x:Key="MenuItemTemplate" Template="{StaticResource MenuItemInnerTemplate}">
<primitives:HierarchicalDataTemplate.ItemTemplate>
<primitives:HierarchicalDataTemplate ItemsSource="{Binding SubMenuItems}" Template="{StaticResource MenuItemInnerTemplate}"/>
</primitives:HierarchicalDataTemplate.ItemTemplate>
</primitives:HierarchicalDataTemplate>
</UserControl.Resources>
<navigation:SfMenu Orientation="Vertical" HorizontalAlignment="Left" VerticalAlignment="Top"
x:Name="SfMenuControl"
ItemTemplate="{StaticResource MenuItemTemplate}"/>
In Code behind I´m setting the ItemsSource to a ObservableCollection of my model.
In the Tapped-Event handler I´m reading the Tag property and therefor get the assigned element from my collection.
Works for the first layer, but NOT for submenu items. Here I do not get the tapped event from my Grid control.
Second try:
In code behind when the SfMenu control is Loaded I´m trying to get the realized SfMenuItem controls via the VisualTree. But also cant get the correct submenu items.
I´m pretty sure that I´m missing something. Could you please give me an advise how to solve this problem?
Thanks in advance and best regards, Gernot