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

Can't sort menuitem by other property but text

2 Answers 22 Views
Menu
This is a migrated thread and some comments may be shown as answers.
bohebolo
Top achievements
Rank 1
bohebolo asked on 03 Aug 2010, 06:04 AM
Is there a way to sort menu items (and subitems) by other property?
Currently i'm binding radmenu to ObservableCollection<T> to populate it.
Where T is my custom class that contain menuId, besides text & icon properties.

What i need is to sort by this menuId instead of text property.
Any help/directions will be appreciated...

thanks.

2 Answers, 1 is accepted

Sort by
0
Accepted
Valeri Hristov
Telerik team
answered on 03 Aug 2010, 01:58 PM
Hi,

RadMenu displays its items in the same order as they appear in the source collection. To change that order you should sort the sorce collection. Since ObservableCollection<T> does not have a Sort method, you could create a CollectionViewSource with Source your observable collection, and sort the CollectionViewSource instead.

All the best,
Valeri Hristov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
bohebolo
Top achievements
Rank 1
answered on 03 Aug 2010, 02:36 PM
thanks Valeri,

It works like a charm, here is how to do it...

in usercontrol.resources:
        <CollectionViewSource x:Name="mainMenuItemsSource">
            <CollectionViewSource.SortDescriptions>
                <compMod:SortDescription PropertyName="MenuID" Direction="Ascending"/>
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>


in code behind:
                mainMenuItemsSource.Source = e.Result;
                mainMenu.ItemsSource = mainMenuItemsSource.View;

EDIT: Don't forget to add this assembly
    xmlns:compMod="clr-namespace:System.ComponentModel;assembly=System.Windows"
Tags
Menu
Asked by
bohebolo
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
bohebolo
Top achievements
Rank 1
Share this question
or