RadMenu MVVM Binding

3 posts, 1 answers
  1. Alexandre
    Alexandre avatar
    2 posts
    Member since:
    Jan 2012

    Posted 30 Apr Link to this post

    Hello,

    I have a very simple piece of code to bind my RadMenu control to an ObservableList of Menus.

    My xaml looks like this:

    <telerik:RadMenu Name:"MainMenu" ItemsSource="{Binding Menus}"/>

    This works fine. In order to display something more interesting, I can add:

    <telerik:RadMenu Name:"MainMenu" ItemsSource="{Binding Menus}" DisplayMemberPath="Name" />

    And I get the Name property of my Menus displayed.

    Now I would like to get a step further as my Menu class has a SubMenus property so I try to play with RadMenuItem styling and this is where I get lost.

    If I write simple code like this, that according to me should do the same as the DisplayMemberPath :

    <telerik:RadMenu Name:"MainMenu" ItemsSource="{Binding Menus}" >

          <telerik:RadMenu.Resources>

                <Style TargetType="telerik:RadMenuItem">

                        <Setter Property="Header" Value="{Binding Name}"/>

                </Style>

           </telerik:RadMenu.Resources>

    </telerik:RadMenu>

    Nothing is displayed on my window when running the code. 

    I have checked everything, I can see in my view that the Menu is created and the items inside, etc... but the RadMenus don't display.

    As soon as I comment out the Style, menus are displayed. As everything else is straightforward in my code, I think I am missing something obvious but I can't find it. There is no error in debug for binding issues or else.

    I use Telerik 2017.1.22.45.

    Thanks for your feedback.

  2. Answer
    Nasko
    Admin
    Nasko avatar
    692 posts

    Posted 03 May Link to this post

    Hi Alexandre,

    Based on the provided description that the control is visualized as expected when the Styles are commented what we believe might be causing your issue is that your Style is not based on the default Style of the RadMenuItem. However, that could only be observed if Implicit Styles are used. So, if you are using them please, check the code below:
    <Style TargetType="telerik:RadMenuItem" BasedOn="{StaticResource RadMenuItemStyle}">
     <Setter Property="Header" Value="{Binding Name}"/>
    </Style>

    If you are not using Implicit Styles, please let us know and we will continue our investigation.

    Hope this helps.

    Regards,
    Nasko
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Alexandre
    Alexandre avatar
    2 posts
    Member since:
    Jan 2012

    Posted 04 May in reply to Nasko Link to this post

    Hi Nasko,

    That was it ! Seems obvious once you know the solution. Thanks for your help.

    Regards,

    Alexandre

Back to Top