Menu click & command pattern & MVVM

4 posts, 0 answers
  1. Mateusz Wolsza
    Mateusz Wolsza avatar
    1 posts
    Member since:
    Oct 2008

    Posted 24 Apr 2009 Link to this post

    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
  2. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 24 Apr 2009 Link to this post

    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.
  3. DevCraft banner
  4. Deepthi
    Deepthi avatar
    7 posts
    Member since:
    Jul 2010

    Posted 30 Aug 2010 Link to this post

    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.
  5. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 31 Aug 2010 Link to this post

    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
Back to Top