How to set current Item

6 posts, 0 answers
  1. Ye
    Ye avatar
    23 posts
    Member since:
    Dec 2010

    Posted 10 Aug 2011 Link to this post

    We want to set one MenuItem in the Items as the current selected item.
    But there is no IsSelected properties in RadMenuItem (it isinternal).
    And we override the RadMenuItem and override the IsHighlighted property.
    Like this:
    public class MenuItemHousas : RadMenuItem
        {
            public MenuItemHousas()
                : base()
            { }
     
            public new bool IsHighlighted
            {
                get { return base.IsHighlighted; }
                set
                {
                    base.IsHighlighted = value;
                }
            }
        }
    It can set the Item highlighted. But it is useless, because the current item doesn't changed.

    What can i do?
    Any sample code is helpful~

    Thanks~
  2. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 12 Aug 2011 Link to this post

    Hi Ye,

    In order to select a menu item you can set the IsCurrent property of the RadMenuItem.

    Best wishes,
    Konstantina
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
  3. DevCraft banner
  4. Ye
    Ye avatar
    23 posts
    Member since:
    Dec 2010

    Posted 15 Aug 2011 Link to this post

    I don't think there is IsCurrent property in RadMenuItem that can be setted.
    This proterty is not public property/
  5. Dani
    Admin
    Dani avatar
    848 posts

    Posted 18 Aug 2011 Link to this post

    Hi Ye,

    RadMenu does not support the concept of selecting the current item. When any of the submenu items is clicked, all submenus close and currently selected item cannot be shown.

    What you can do to try and change this behavior, is to create your own IsCurrent DependencyProperty. In your MenuItemHousas override the ChangeVisualState method and call GoToState Current/NotCurrent state. Then, update the visual states in the style for the RadMenuItem (remember there are four templates - TopLevelHeaderTemplate, TopLevelItemTemplate, SubMenuHeaderTemplate, SubMenuItemTemplate) to reflect the new visual state change.

    On ItemClick of RadMenuItem, you can wire up your own logic to set IsCurrent of the RadMenuItem to True or False.

    I hope this helps.

    Regards,
    Dani
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
  6. Ye
    Ye avatar
    23 posts
    Member since:
    Dec 2010

    Posted 18 Aug 2011 Link to this post

    I can't call GoToState method.

    Do you have any example, or any code?
  7. Dani
    Admin
    Dani avatar
    848 posts

    Posted 24 Aug 2011 Link to this post

    Hello Ye,

    The purpose of using the ChangeVisualState method is to include your new state, IsCurrent, in the visual states of your custom RadMenuItem. The method basically, contains a series of "if" blocks or "switch" statements that determine which visual state the menu item is in. To do that you have to call the GoToState method for the new  visual state that your RadMenuItem is going to possess.

    When calling the method, call base.ChangeVisualState() to have the rest of the visual states functioning. Consider the following example:

    public override void ChangeVisualState(bool useTransitions)
            {       
      
                if (this.IsCurrent)
                {
                     this.GoToState(useTransitions, new string[] { "Current", "NotCurrent" });
                }
                        else
                {
                     this.GoToState(useTransitions, "NotCurrent");
                }
      
             }


    I hope this helps.

    Regards,
    Dani
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Back to Top
DevCraft banner