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

Menu click & command pattern & MVVM

3 Answers 224 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Mateusz Wolsza
Top achievements
Rank 2
Mateusz Wolsza asked on 24 Apr 2009, 09:25 AM
Hi,
I'm developing an application in MV-VM pattern. I'm also using a command pattern from SilverlightExtensions, and it seems like the click doesn't fire up properly.

For example code like this:
<Button Content="Save" localInput:CommandService.Command="Save" localInput:CommandService.CommandParameter="{Binding ItemToEdit}" />
works perfectly in my case, but
<telerik:RadMenuItem Header="Save" localInput:CommandService.Command="Save" localInput:CommandService.CommandParameter="{Binding ItemToEdit}" />
doesn't work at all.

I don't want do do an event handler in code behind, so is there any solution for using commands in Telerik Menu control?

Best Regards
Mateusz Wolsza

3 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 24 Apr 2009, 10:31 AM
Hello Mateusz Wolsza ,

After some research I find out that SLExtension Commands attach to some ButtonBase.Click event if the element is of type ButtonBase, KeyDown if the type of the element is TextBox, or MouseLeftButtonUp in all other cases. But RadMenuItem handles this event so the commanding mechanism won't receive this event (so it won't work).
However RadControls for Silverlight 2 are using RoutedEvents. This means that RadMenuItem.Click event bubbles up on the Visual tree and can be handled where you need it.
For example you can handle all RadMenuItem.Click events in a single method and  you don't need to attach this handler to all items. You can attach it on the RadMenu (or any visual parent).

Here is an example:
using Telerik.Windows; //you will need this namespace to see the AddHandler extension method  
public class Page  
{  
   public Page()  
   {  
      InitializeComponent();  
      radMenu1.AddHandler(RadMenuItem.ClickEvent, new RoutedEventHandler(OnMenuItemClick));  
   }  
 
   private void OnMenuItemClick(object sender, RoutedEventArgs e)  
   {  
    RadRoutedEventArgs args = e as RadRoutedEventArgs;  
    RadMenuItem menuItem = e.OriginalSource as RadMenuItem;  
    if (menuItem.Tag == "File")  
    {  
        // Do something  
    }  
   }  

Let us know if you need more information.

Sincerely yours,
Hristo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Deepthi
Top achievements
Rank 1
answered on 30 Aug 2010, 05:44 PM
Hi,

Is this the same case with the RadTreeView Control. I am not able to use command binding. I am using the TreeViewItem control from Q1 and a version 2010.1.422.1030. Let me know in case if you need any more information. Please let me know the solution as soon as possible.

Thank you,
Deepthi Sree.
0
Hristo
Telerik team
answered on 31 Aug 2010, 08:16 AM
Hi Deepthi,

Can you be more precise about your question?
If you are asking whether RadTreeView is using Routed Events - then the answer is yes.
Please send us sample project so that we can investigate it.

All the best,
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
Mateusz Wolsza
Top achievements
Rank 2
Answers by
Hristo
Telerik team
Deepthi
Top achievements
Rank 1
Share this question
or