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

Binding with RadMenuGroupItem and RadMenuItem based on condition

1 Answer 115 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Darko
Top achievements
Rank 1
Darko asked on 27 Jul 2016, 06:32 AM
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

1 Answer, 1 is accepted

Sort by
0
Accepted
Polya
Telerik team
answered on 29 Jul 2016, 11:52 AM
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:
https://github.com/telerik/xaml-sdk/tree/master/Menu/Customization_MVVM

Hope this helps.

Regards,
Polya
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
Menu
Asked by
Darko
Top achievements
Rank 1
Answers by
Polya
Telerik team
Share this question
or