Menu Customization Sample - Command

2 posts, 0 answers
  1. Alex Martin
    Alex Martin avatar
    11 posts
    Member since:
    May 2010

    Posted 25 Feb 2013 Link to this post

    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?
  2. Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 27 Feb 2013 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top