Binding with RadMenuGroupItem and RadMenuItem based on condition

2 posts, 1 answers
  1. Darko
    Darko avatar
    16 posts
    Member since:
    Sep 2008

    Posted 27 Jul 2016 Link to this post

    Dear Telerik-Team,

    we have a RadMenu that has bound his data over a ViewModel. Depending on the data we want to generate RadMenuGroupItems or RadMenuItems.
    The bound data class is this:

    public class MenuItem
            public List<MenuItem> SubItems { get; set; }
            public string Text { get; set; }
            public Type EditUserControlType { get; set; }
            public Action<object> Navigate;
            public int RowIndex { get; set; }
            public int ColumnIndex { get; set; }

            public MenuItem()
                SubItems = new List<MenuItem>();

    if the MenuItem has SubItems we want that a RadMenuGroupItem is dynamically created. If the MenuItem has no SubItems we want that a RadMenuItem is created.
    Is there a similar way of Item Creation like the dynamic assignemnt of Styles over the property "ItemContainerStyleSelector". We need something called "ItemContainerControlSelector"
    but we didn't find anything in the documentation.

    Important: We don't want to create the items dynamicalle in code behind of the view. We want to assign this logic via XAML in the View.

    How can we do that?

    Thanks for your help.

    Kind regards
  2. Answer
    Polya avatar
    255 posts

    Posted 29 Jul 2016 Link to this post

    Hello Darko,

    Thank you for contacting us.

    When working with dynamic data the RadMenu container generator creates RadMenuItems as containers for its children. This is done in the GetContainerForItemOverride method of the control. As each ItemsControl should specify in this method what type its item containers will be. You might create a custom RadMenu and override this method to return RadMenuGroupItems or RadMenuItems but never both.

    That said, I suggest using a custom ItemContainerStyleSelectror and style the data items that have SubItems in the desired way.

    We have a great example demonstrating how to achieve that in our developer focused examples:

    Hope this helps.

    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top