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

Menu Customization Sample - Command

1 Answer 55 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Alex Martin
Top achievements
Rank 1
Alex Martin asked on 25 Feb 2013, 05:58 PM
I like the sample Menu Customization in with reference WPF Demo however the sample focus only on the display. How would I got about adding Command binding to this sample?  

If I add a Command property of type ICommand to your MenuItemViewModel and can't bind to the newly added property since the MenuItemViewModel is not a Dependency object.  

Any suggestion?

1 Answer, 1 is accepted

Sort by
0
Rosen Vladimirov
Telerik team
answered on 27 Feb 2013, 10:47 AM
Hello Alex Martin,

If you have defined property Command of type ICommand in MenuItemViewModel, most probably you want to use it as a source of your Binding operation. Lets say you have added a CopyCommand class in your application that inherits ICommand. You can use it in your XAML in the following way:
<local:CopyCommand x:Key="CopyCommand"/>
....
<local:MenuItemViewModel Content="Bar" Command="{StaticResource CopyCommand}" />

With the lines above you are setting Command property of the MenuItemViewModel object. Now you have to set the Binding in all MenuItem Styles you need:
<Setter Property="Command" Value="{Binding Command}"/>

And that's it, you are now able to use your command.

Hopefully this helps.

Kind regards,
Rosen Vladimirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Menu
Asked by
Alex Martin
Top achievements
Rank 1
Answers by
Rosen Vladimirov
Telerik team
Share this question
or