Can't sort menuitem by other property but text

3 posts, 1 answers
  1. bohebolo
    bohebolo avatar
    31 posts
    Member since:
    Aug 2010

    Posted 03 Aug 2010 Link to this post

    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. Answer
    Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 03 Aug 2010 Link to this post

    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
  3. DevCraft banner
  4. bohebolo
    bohebolo avatar
    31 posts
    Member since:
    Aug 2010

    Posted 03 Aug 2010 Link to this post

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