How do I pass command parameters to commands associated with RadMenuItems?

6 posts, 0 answers
  1. John
    John avatar
    7 posts
    Member since:
    Nov 2010

    Posted 04 Mar Link to this post

    Hi:

    I'm using the Telerik CUSTOM_MVVM_WPF example to build out a series of menus using

    MVVM and RadMenuItems.

     

    I'm having difficulty building out the MVVM  so that I can pass parameters to the

    commands associated with the individual menu items.

    How d I extend the implementation to achieve this?

     

    Thanks,

    JohnB

  2. Nasko
    Admin
    Nasko avatar
    685 posts

    Posted 08 Mar Link to this post

    Hello John,

    You could add a Command inside the MenuItemViewModel and bind it to the Command property of the MenuItem. After that you need to  implement some custom logic for the specific items inside the Action that is executed when the command is invoked. As for the parameter you could easily pass it to the Action using the CommandParameter property of the RadMenuItem.

    We have modified the sample in order to demonstrate you the described above approach.

    If you want to pass some specific parameter for each item you could also add property for the parameter inside the MenuItemViewModel and bind it to the CommandParameter of the RadMenuItem.

    We hope this will help you.

    Regards,
    Nasko
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. John
    John avatar
    7 posts
    Member since:
    Nov 2010

    Posted 10 Mar in reply to Nasko Link to this post

    Nasko:  Is there an issue with the zipped project, or am I missing something.

    The archive seems to be empty of .cs and .xaml files.

     

    Thanks,

    JB

  4. Nasko
    Admin
    Nasko avatar
    685 posts

    Posted 10 Mar Link to this post

    Hi John,

    We have noticed that you are having troubles with the unzipping of the exact same project attached in this forum thread. As your issue is related with this thread as well, please check the answer we have provided in the other forum thread.

    Hope this helps.

    Regards,
    Nasko
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  5. John
    John avatar
    7 posts
    Member since:
    Nov 2010

    Posted 10 Mar in reply to Nasko Link to this post

    Hi Nasko:

    This is a good start, but could you further extend this so:

        - I can see the parameter being set on a specific menu item

        - see how to consume the parameter in a custom command?

     

    Consider the following custom command I have attached to a menu:

    using System;
    using System.Windows;
    using System.Windows.Input;
    public class ApplicationMaximizeCommand : ICommand

    {
       public event EventHandler CanExecuteChanged;

       public bool CanExecute(object parameter)
       {
         return true;
       }
       public void Execute(object parameter)
       {
         //MessageBox.Show("Application Shutdown Command Clicked!!!");
         // For example with this instance I would like to pull the
         // Main Application window from the command parameter...
         MainFrameWindow.WindowState = WindowState.Maximized;
       }
       public ApplicationMaximizeCommand()
       {
       }

    }

    This is what my xaml looks like:

    <viewModel:MenuItemVM Name="AppMaxe" Content="SomeImage.png" Type="Image">
       <viewModel:MenuItemVM.Command >
         <commands:AppMaxCommand />
       </viewModel:MenuItemVM.Command>
    </viewModel:MenuItemVM>

     

    Thanks,

    JohnB

  6. Nasko
    Admin
    Nasko avatar
    685 posts

    Posted 13 Mar Link to this post

    Hi John,

    We have modified the sample in order to demonstrate you how to pass a specific parameter for the separate menu items - please, check it.

    As already explained in my initial response a new additional property needs to be added inside the MenuItemViewModel and that property needs to be bound to the CommandParameter property of the MenuItem. Please, notice that if you need to set values through a Binding for the added inside the MenuItemViewModel property you need to make it a DependencyProperty.

    Hope this helps.

    Regards,
    Nasko
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top