Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
290
XamRibbon.ApplicationMenu2010 mvvm binding
posted

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

Parents
No Data
Reply
  • 54937
    Suggested Answer
    Offline posted

    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.

Children