Hello, I am trying to integrate this very well documented MVVM example. Unfortunately the hierarchical variant is missing the code-behind example for the data binding.
https://help.syncfusion.com/wpf/navigation-drawer/populating-data?cs-save-lang=1&cs-lang=csharp
As a WPF newbie I have a hard time translating this part to C#.
How can I bring this part in particular to C#?
Thanks for any help!
Stefan
<Window.Resources>
<Style x:Key="ItemStyle" TargetType="syncfusion:NavigationItem">
<Setter Property="Icon" Value="{Binding Icon}" />
<Setter Property="DisplayMemberPath" Value="Item" />
<Setter Property="ItemsSource" Value="{Binding SubItems}" />
</Style>
</Window.Resources>
<syncfusion:SfNavigationDrawer
x:Name="navigationDrawer"
DisplayMemberPath="Item"
ItemContainerStyle="{StaticResource ItemStyle}"
ItemsSource="{Binding Items}">
</syncfusion:SfNavigationDrawer>
Hi Stefan,
Query: How can I bring a hierarchical Data Binding sample in C#(Code Behind)?
We have prepared a hierarchical data binding sample for SfNavigationDrawer in the C# (Code-Behind file).
Please get the sample from the attachment.
Please check and let us know the details.
Regards,
Vijayakumar V
Hi Stefan,
Thanks for the update. Please let us know if you have any further queries. We are happy to help you.
Regards,
Vijayakumar V
I have another question in relation to the above example (Populating data via MVVM). How can I set a "Command Binding" to each Item or the whole navigationDrawer for handling a "ClickCommand".
I somehow tried to create Setters to the NavigationItem.CommandProperty like You did below to the NavigationItem.DisplayMemberPathProperty - but unsuccessful.
Thank You a lot!
Stefan
ViewModel viewModel = new ViewModel();
this.DataContext = viewModel;
Style navigationItemStyle = new Style(typeof(NavigationItem));
navigationItemStyle.Setters.Add(new Setter(NavigationItem.DisplayMemberPathProperty, "Item"));
navigationItemStyle.Setters.Add(new Setter(NavigationItem.ItemsSourceProperty, new Binding("SubItems")));
SfNavigationDrawer navigationDrawer = new SfNavigationDrawer();
navigationDrawer.ItemsSource = viewModel.Items;
navigationDrawer.DisplayMode = DisplayMode.Expanded;
navigationDrawer.DisplayMemberPath = "Item";
navigationDrawer.IconMemberPath = "Icon";
navigationDrawer.ItemContainerStyle = navigationItemStyle;
Hi Stefan,
Query: How can I set a "Command Binding" to each Item or the whole NavigationDrawer for handling a "ClickCommand" in C#(Code Behind)?
We had already shared the details for Command binding to navigation items in the UG document. Please refer to the below UG link
UG link: https://help.syncfusion.com/wpf/navigation-drawer/commands-and-events#commands
For setting the command binding in the C# file(code-behind), We have prepared a sample along with the hierarchical data binding. Please get the sample from the attachment.
Please check and let us know if you have further queries.
Regards,
Vijayakumar V
Thank You again for the amazing support!
This two lines are what I needed:
navigationItemStyle.Setters.Add(new Setter(NavigationItem.CommandProperty,viewModel.ClickCommand));
navigationItemStyle.Setters.Add(new Setter(NavigationItem.CommandParameterProperty, new Binding("Item")));
Hi Stefan,
We are glad to hear that the solution we provided was helpful to you. Please let us know if you require any further assistance.
Regards,
Vijayakumar V