Hello,
How to bind a collection to sub menu items, properly. I used the ItemsSource and the XamMenuItem.ItemContainerStyle. But it doesn't work as expected. Wrong Header Text and wrong hover style.
<ig:XamMenuItem Header="Recent Configurations ..." ItemsSource="{Binding RecentLoadedConfigs}"> <ig:XamMenuItem.Icon> <Image Source="/Resources/Icons/OpenFolder_16x.png"></Image> </ig:XamMenuItem.Icon> <ig:XamMenuItem.ItemContainerStyle> <Style TargetType="ig:XamMenuItem"> <Setter Property="Header" Value="{Binding Header}"/> <Setter Property="Command" Value="{Binding ClickCommand}"/> </Style> </ig:XamMenuItem.ItemContainerStyle> </ig:XamMenuItem>
Hello Bin,
With an MVVM list in the way that is demonstrated in the sample I sent you, I do not believe it is currently possible to use a XamMenuSeparator. I can offer an alternative in this case though, and that is to bind to a List<object> instead, and construct your XamMenuItems and XamMenuSeparators in code.
I am attaching a modified version of the sample I sent you with a new XamMenuItem that binds to a collection of XamMenuItems and XamMenuSeparators from the ViewModel. I hope this helps.
Please let me know if you have any other questions or concerns on this matter.
5633.XamMenuItemMVVMBinding.zip
That works perfectly. Is it also possible to use XamMenuSeparator in the MVVM list? If yes, how?
It would be great, if that sample will also be published in the Sample Browser and in the Help.
In order to add the click command, you should utilize the DefaultItemsContainer and place a XamMenuItem in the resulting ItemContainerTemplate. You can bind the Command there.
I am attaching a modified version of the sample project I sent you to demonstrate this.
0513.XamMenuItemMVVMBinding.zip
Thanks for the sample. How can I add the click command? So, when the user clicks on an item, something is happening.
I would first recommend that you take a look at the following documentation about binding XamMenu and XamMenuItem items: https://es.infragistics.com/help/wpf/xammenu-binding-to-data. In general, you will want to use the HierarchicalItemTemplate and ItemTemplate properties rather than the ItemContainerStyle property. I am attaching a sample project to demonstrate this.
Regarding the styling issues you are seeing, I believe this could be due to some theming, as it appears you are likely applying the MetroDark theme. WPF elements only keep a single local style, and so by applying your own ItemContainerStyle, you are reverting back to the default theme in some cases. You would need to base on the MetroDark XamMenuItem theme in order to keep the styling, which can be found in the MetroDark.xamMenu.xaml file commonly found at the following directory with Infragistics controls installed:
C:\Program Files (x86)\Infragistics\2021.2\WPF\Themes\MetroDark
XamMenuItemMVVMBinding.zip