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

Programmatically select menu item for mvvm prism application

7 Answers 308 Views
Menu
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 08 Nov 2011, 07:30 PM
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.

7 Answers, 1 is accepted

Sort by
0
Accepted
Konstantina
Telerik team
answered on 09 Nov 2011, 09:39 AM
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 >>
0
David
Top achievements
Rank 1
answered on 09 Nov 2011, 12:56 PM
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.
0
Konstantina
Telerik team
answered on 11 Nov 2011, 01:52 PM
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 >>
0
David
Top achievements
Rank 1
answered on 13 Nov 2011, 07:49 AM
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.
0
Konstantina
Telerik team
answered on 15 Nov 2011, 01:38 PM
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 >>
0
David
Top achievements
Rank 1
answered on 15 Nov 2011, 02:18 PM
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
0
Konstantina
Telerik team
answered on 18 Nov 2011, 11:09 AM
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 >>
Tags
Menu
Asked by
David
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
David
Top achievements
Rank 1
Share this question
or