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
3220
xamMenuItem: Bind sub items MVVM
posted

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>

Parents
No Data
Reply
  • 34830
    Offline posted

    Hello Bin,

    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

    Please let me know if you have any other questions or concerns on this matter.

    XamMenuItemMVVMBinding.zip

Children