RadMenu MVVM style/template selectors

4 posts, 1 answers
  1. SB
    SB avatar
    10 posts
    Member since:
    Apr 2016

    Posted 27 Oct 2016 Link to this post

    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.

  2. Stefan X1
    Admin
    Stefan X1 avatar
    710 posts

    Posted 01 Nov 2016 Link to this post

    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!
  3. SB
    SB avatar
    10 posts
    Member since:
    Apr 2016

    Posted 02 Dec 2016 in reply to Stefan X1 Link to this post

    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.

     

  4. Answer
    Stefan X1
    Admin
    Stefan X1 avatar
    710 posts

    Posted 06 Dec 2016 Link to this post

    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.
Back to Top