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

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

5 Answers 583 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 04 Mar 2017, 03:51 PM

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

5 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 08 Mar 2017, 11:13 AM
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.
0
John
Top achievements
Rank 1
answered on 10 Mar 2017, 06:07 AM

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

0
Nasko
Telerik team
answered on 10 Mar 2017, 11:46 AM
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.
0
John
Top achievements
Rank 1
answered on 10 Mar 2017, 03:06 PM

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

0
Nasko
Telerik team
answered on 13 Mar 2017, 08:10 AM
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.
Tags
General Discussions
Asked by
John
Top achievements
Rank 1
Answers by
Nasko
Telerik team
John
Top achievements
Rank 1
Share this question
or