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

MVVM Item click

4 Answers 214 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Ruban
Top achievements
Rank 1
Ruban asked on 05 Oct 2009, 05:31 PM
HI,
I'm new to Silverlight and MVVM.
What I'm trying to do is bind an event for the ItemClick for the ContextMenu to the ViewModel.
It doesn't seem to call the delegate in the viewmodel when I apply to the Telerik Context Menu click but it does work for a standard control such as Hyperlink.
Any ideas?
The view:

<

 

UserControl x:Class="Module.Views.PageMenuView"

 

 

 

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

 

 

 

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

 

 

 

xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"

 

 

 

xmlns:cal="clr-namespace:Microsoft.Practices.Composite.Presentation.Commands;assembly=Microsoft.Practices.Composite.Presentation"

 

 

 

>

 

 

 

 

<Grid x:Name="LayoutRoot" Background="White">

 

 

 

 

<StackPanel Orientation="Vertical">

 

 

 

 

<HyperlinkButton x:Name="SettingLink" Content="Click" cal:Click.Command="{Binding MenuOptionCommand}" Foreground="Blue"/>

 

 

 

 

<ToggleButton Content="Export" HorizontalAlignment="Left"

 

 

 

IsChecked="{Binding IsOpen, ElementName=context, Mode=TwoWay}">

 

 

 

 

<telerikNavigation:RadContextMenu.ContextMenu>

 

 

 

 

<telerikNavigation:RadContextMenu x:Name="context" Placement="Bottom" telerikNavigation:RadContextMenu.ContextMenu.="{Binding MenuOptionCommand}">

 

 

 

 

<telerikNavigation:RadMenuItem Header="Export to Excel" />

 

 

 

 

<telerikNavigation:RadMenuItem Header="Export to PDF" />

 

 

 

 

</telerikNavigation:RadContextMenu>

 

 

 

 

</telerikNavigation:RadContextMenu.ContextMenu>

 

 

 

 

</ToggleButton>

 

 

 

 

</StackPanel>

 

 

 

 

</Grid>

 

</

 

 

UserControl>

 

 

4 Answers, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 09 Oct 2009, 10:33 AM
Hi Ruban,

The Prism Click.Command attached behavior is working only with a Control that has a click event (base type is ButtonBase). The base type of the RadContextMenu is ItemsControl, hence, it is not possible to be attached such a delegate command to the RadContextMenu.

Sincerely yours,
Kaloyan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ruban
Top achievements
Rank 1
answered on 09 Oct 2009, 10:35 AM
Found a solution, it is possible by writing a command behavior.
0
Claudio
Top achievements
Rank 1
answered on 05 Nov 2010, 07:01 PM
I have been trying to accomplish the same thing [Get MenuItem that was clicked via a command] and I have found that the Telerik ContextMenu does not support that. Here is an article with source code providing a behavior to get this done.

http://bhaidar.net/cs/archive/2010/01/01/commanding-for-radcontextmenu-in-composite-application-library-prism.aspx

However, the date of the arcticle is January, 2010, and I was wondering if this is still the only workaround.


Thanks in advance,


Claudio Sanchez
0
Hristo
Telerik team
answered on 10 Nov 2010, 09:35 AM
Hello Claudio,

RadMenuItem have Command property of type ICommand as well as CommandTarget and CommandParameter. You can easily bind them to your data item.

Let us know if you need additional information.

Regards,
Hristo
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
Tags
Menu
Asked by
Ruban
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
Ruban
Top achievements
Rank 1
Claudio
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or