This is a migrated thread and some comments may be shown as answers.

RadMenu MVVM Binding

2 Answers 197 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Alexandre
Top achievements
Rank 1
Alexandre asked on 30 Apr 2017, 06:19 AM

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 Answers, 1 is accepted

Sort by
0
Accepted
Nasko
Telerik team
answered on 03 May 2017, 12:29 PM
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.
0
Alexandre
Top achievements
Rank 1
answered on 04 May 2017, 05:09 AM

Hi Nasko,

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

Regards,

Alexandre

Tags
Menu
Asked by
Alexandre
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Alexandre
Top achievements
Rank 1
Share this question
or