Hi Team,
I added added a XamMenu to my page. I hen added in Xaml few Menu items. One of them has sub items which are bound to ObservableCollection of type string.
<ig:XamMenuItem x:Name="openRecent" Header="Open Recent" Style="{StaticResource DarkXamMenu}" ItemsSource="{Binding RecentWells}"></ig:XamMenuItem>
I encountered two problems:
1. The sub menu items do not inherit the style that I applied to the parent menu item. How do I apply the same style to the sub items that are generated dynamically?2. I'd like the click event of these submenu items to be bound to a command in a view model. Any new item that will be generated based on the changes in the Observable collection should trigger this command and pass the text of the item (header?) as an argument. This is basically a try to create an "Open Recent File" menu item where recent file names will be shown to the user...How do I go about these two problems?ThanksMichal
I think I can now answer my Own Question. I now do not bind the ItemsSource to ObservableCollection but rather create the XamMenuItem(s) during Loaded event of the control:
this.openRecent.Items.Clear(); //ManuItem creted in xaml and given name foreach (var well in _vm.RecentWells) //_vm is this.DataContext as MyViewModel and RecentWells //is my ObservableCollection { var newItem = new XamMenuItem(); newItem.Header = well; newItem.Click += _vm.OpenRecent; newItem.Style = FindResource("XamMenuItemStyle") as Style; this.openRecent.Items.Add(newItem); }This way I bind each of the items Click event to a void in a ViewModel. At the same time I bind the style to a style that I created in StaticResources. Hope it will by helpful to someone else
Hello Michal,
Thank you for posting on our forums and I am happy to see that you have found the solution and shared it so our community members will benefit from the information here.
Thank you for using Infragistics components.
Sincerely,
Tihomir TonevSoftware DeveloperInfragistics