Programmatically select menu item for mvvm prism application

8 posts, 1 answers
  1. David
    David avatar
    7 posts
    Member since:
    Nov 2011

    Posted 08 Nov 2011 Link to this post

    Hello I have a prism/mvvm style application and am using the RadMenu control. I also have a view/view model pair in one project and another view/view model pair for my RadMenu control in another project. Basically I would like to use the event aggregator to send an event to the view model for the RadMenu (the view model that is paired with the view that the RadMenu sits inside of). So that the RadMenu's view model can notify the RadMenu to switch to a different RadMenuItem programmatically. I think I can use a blend behavior to contain the behavior I'm looking to reproduce, but I cannot find a method in the RadMenu that will allow me to programmatically select a specific menu item.

    If the control does not support this now, is there a work around? Thanks.
  2. Answer
    Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 09 Nov 2011 Link to this post

    Hello David,

    In order to select an item from the RadMenu you have to set its IsCurrent property to True.

    Hope this helps.

    Best wishes,
    Konstantina
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. David
    David avatar
    7 posts
    Member since:
    Nov 2011

    Posted 09 Nov 2011 Link to this post

    Thanks for the answer. Also instead of just an overview is there an msdn style reference for this control and all your controls infact. Thanks again.
  5. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 11 Nov 2011 Link to this post

    Hi David,

    Yes, in the API Reference part of the our help documentation you could find a structure information for all the classes, properties and methods in the namespaces.

    Best wishes,
    Konstantina
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  6. David
    David avatar
    7 posts
    Member since:
    Nov 2011

    Posted 13 Nov 2011 Link to this post

    So I tried using the IsCurrent property and it worked, but only the first time. Then it stopped working although by using breakpoints I can see that the code is continueing to run. And what I mean by stopped working is that the desired menu item no longer got highlighted. Here's my code
    private bool _commentaryMenuItemIsCurrent;
    public bool CommentaryMenuItemIsCurrent
    {
        get { return _commentaryMenuItemIsCurrent; }
        set 
        {
            _commentaryMenuItemIsCurrent = value;
      
            if (CommentaryMenuItemIsCurrent)
                ReportsMenuItemIsCurrent = false;
                      
            RaisePropertyChanged("CommentaryMenuItemIsCurrent");
        }
    }
    <telerik:RadMenu Name="radMenu2" Height="23" VerticalAlignment="Top">
        <telerik:RadMenuItem Header="Commentary" IsCurrent="{Binding CommentaryMenuItemIsCurrent}">
            <TextBlock Text="testing commentary menu item"></TextBlock>
        </telerik:RadMenuItem>
        <telerik:RadMenuItem Header="Reports" IsCurrent="{Binding ReportsMenuItemIsCurrent}"/>
                  
    </telerik:RadMenu>

    The CommentaryMenuItemIsCurrent property is bound to the IsCurrent property on the radmenuitem. I am using the mvvm pattern.
  7. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 15 Nov 2011 Link to this post

    Hi David,

    Sorry, I am not sure I can understand correctly. How exactly do you expect the RadMenuItem to behave? When are you changing the IsCurrent property? Could you please elaborate more on what exactly you are trying to achieve. In that way we will be able to provide you with the best solution for your case.

    Greetings,
    Konstantina
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  8. David
    David avatar
    7 posts
    Member since:
    Nov 2011

    Posted 15 Nov 2011 Link to this post

    I am trying to have the menu item highlight every time i programmatically set iscurrent. Right now the highlight of the menu item only happens one time. Then it stops happening. So i need the highlight to happen every time i programmatically set iscurrent to true
  9. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 18 Nov 2011 Link to this post

    Hi David,

    The IsCurrent property is meant to be used on the RadContextMenu, to identify a default item. To make it work on the RadMenu it has to be used for one of the child items, not the top level item, because when the menu is closed, the value of the IsCurrent property is cleared. However, to make it work you need to set the Mode of the binding to TwoWay. Also, a better approach will be the menu's items to be set through ViewModel also, instead statically in XAML, as then the top level item also gets the focus, because it inherits the property from its children.

    Hope this clarifies the matter.

    Kind regards,
    Konstantina
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Back to Top
UI for WPF is Visual Studio 2017 Ready