Hi
I am building WPF Prism/MVVM app and would like to use XamRibbon.ApplicationMenu2010 as application menu.
I have multiple modules adding its menu items to ShellViewModel.NavigationManager.TreeMenu collection. then I bind
ApplicationMenu2010 ItemsSource to NavigationManager.TreeMenu collection:
<igRibbon:ApplicationMenu2010 ItemsSource="{Binding NavigationManager.TreeMenu}" ItemTemplate="{StaticResource MenuTemplate}">
I use data template to render ApplicationMenu2010Item as ApplicationMenu2010Item:
<DataTemplate x:Key="MenuTemplate"> <igRibbon:ApplicationMenu2010Item Header="{Binding Menu.Caption}"> </igRibbon:ApplicationMenu2010Item> </DataTemplate>
Question:
How can I add support for ApplicationMenu2010Item.Content and ApplicationMenu2010Separator using binding to viewModel and data templates?
Thank you Dmitri
The ApplicationMenu2010 has a property named InitialSelectedTabItem. You would set/bind this property to the item that should be selected when the menu is opened - so one of the items from the collection that you are binding to the ItemsSource.
Thank you, I was able to build app menu as complex as I need by binding app menu to
ObservableCollection<Control> _app2010Menu = new ObservableCollection<Control>();
public ObservableCollection<Control> App2010Menu { get { return _app2010Menu; } }
I populated App2010Menu with ApplicationMenu2010Item,ApplicationMenu2010Separator and ApplicationMenu2010Item with content:
App2010Menu.Add(new ApplicationMenu2010Item(){Header = "Test1"});
App2010Menu.Add(new ApplicationMenu2010Item(){Header = "Test2"});
App2010Menu.Add(new ApplicationMenu2010Separator());
var i = new ApplicationMenu2010Item() {Header = "Test4"};
i.Content = new NavView1();
App2010Menu.Add(i);
i = new ApplicationMenu2010Item() { Header = "Test5" };
i.Content = new NavView2();
App2010Menu.Add(new ApplicationMenu2010Item() { Header = "Test5" });
App2010Menu.Add(new ApplicationMenu2010Item(){Header = "Test6"});
<igRibbon:ApplicationMenu2010 ItemsSource="{Binding NavigationManager.App2010Menu}"/>
One more question: how can I select a specific "ApplicationMenu2010Item with content" when I open app menu?
The ApplicationMenu2010 is an ItemsControl. The ItemTemplate of an ItemsControl is not meant to define an instance of the container (the ApplicationMenu2010Item in this case, the ListBoxItem in the case of a ListBox, etc.); instead the ItemTemplate is meant to define the DataTemplate that represents the content/header of the container. So you should not be using that to try and define an instance of the container because that will just end up being an element hosted by the ContentPresenter within the container (e.g. an ApplicationMenu2010Item hosted within the ContentPresenter that represents the Header of the ApplicationMenu2010Item that is created to represent the item). Instead, you should use the ItemContainerStyle property of an ItemsControl to define the setters to associate the properties of the container with the properties of the data items. e.g.
<igRibbon:ApplicationMenu2010.ItemContainerStyle> <Style TargetType="igRibbon:ApplicationMenu2010Item"> <Setter Property="Header" Value="{Binding Menu.Caption}" /> </Style></igRibbon:ApplicationMenu2010.ItemContainerStyle>
Now with regards to supporting/using an ApplicationMenu2010Separator that is not as easy. ItemsControls only create a single container type - e.g. MenuItem only creates MenuItem even though it can contain a Separator. So currently the only way to have a separator (ApplicationMenu2010Separator is just a derived Separator that has styling consistent with the ApplicationMenu2010) is to either have an ApplicationMenu2010Separator in the collection that you are binding to the ItemsSource or to not bind the ItemsSource and populate the Items collection with ApplicationMenu2010Item and ApplicationMenu2010Separator/Separator instances.