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

RadMenu MVVM style/template selectors

3 Answers 157 Views
Menu
This is a migrated thread and some comments may be shown as answers.
SB
Top achievements
Rank 1
SB asked on 27 Oct 2016, 05:16 PM

I have been looking through the Telerik RadMenu WPF demos and found the Customization_MVVM_WPF demo.I have a couple of questions with regard to this demo that I hope someone can help me with.

Question:
The MVVM demo has a class "MenuItemContainerTemplateSelector" that does not appear to be used by the demo. I can see that the 'MenuItemStyleSelector' class is used, but am curious when to use the MenuItemContainerTemplateSelector as opposed to the MenuItemStyleSelector? Is there a demo where this MenuItemCoontainerTemplateSelector class is used which I can take a look at the implementation?

 

What I am trying to accomplish:

I need to create a RadMenu which dynamically binds to a collection of ViewModels (RadMenuItems) and uses DataTemplates or styles to tell 'how' to display each of the ViewModels. Are there examples demonstrating this which I have not yet found? The Customization_MVVM_WPF demo somewhat covers this, but attempting to move the MenuItemsSource in this demo out of the XAML and into a collection of ViewModels which the RadMenu binds to seems to not work.

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 01 Nov 2016, 12:24 PM
Hi Sedric,

Generally speaking, this topic is discussed in the Template and Style Selectors article. Can you please check it out? As to determining when to use a template or a style selector, this depends on whether you need to modify the default appearance of the control, or you need to specify custom element in the predefined template. More information can be found in the following resources:

- DataTemplateSelector
- StyleSelector

Hopefully, this clarifies your concerns.

Regards,
Stefan X1
Telerik by Progress
Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
0
SB
Top achievements
Rank 1
answered on 02 Dec 2016, 05:56 PM

Thank you for the reply.

I was hoping for an example that uses the "MenuItemContainerTemplateSelector" class found in the Customization_MVVM_WPF demo. Also, it would be ideal if the example would have the menu items bound to view models rather than declared in the xaml.

 

0
Accepted
Stefan
Telerik team
answered on 06 Dec 2016, 12:41 PM
Hi Sedric,

Thanks for this clarification.

Indeed, in the referred SDK Example the MenuItemContainerTemplateSelector class is not used. It is, however, left so the user can easily apply it through the ItemTemplateSelector of RadMenu. As to adding the items programmatically, you need to ensure that the UI is notified when the items are added. So, if you are using an ObservableCollection as a source collection of RadMenu, the control should populate the added menu items as expected. If it is still not, may I kindly ask you to demonstrate the approach you are using for adding the items?

Regards,
Stefan X1
Telerik by Progress
Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
Tags
Menu
Asked by
SB
Top achievements
Rank 1
Answers by
Stefan
Telerik team
SB
Top achievements
Rank 1
Share this question
or