MVVM RadMenu Binding the command

2 posts, 0 answers
  1. hamish
    hamish avatar
    44 posts
    Member since:
    Jun 2007

    Posted 30 Apr 2014 Link to this post

    I am trying to bind a dynamically generated menu. I have set up the following style:

    Style x:Key="MenuItemStyle" TargetType="telerik:RadMenuItem">
            <Setter Property="Header" Value="{Binding Header}" />
            <Setter Property="IsCheckable" Value="{Binding IsCheckable}" />
            <Setter Property="IsSeparator" Value="{Binding IsSeparator}" />
            <Setter Property="IsChecked" Value="{Binding IsChecked}" />
            <Setter Property="Icon" Value="{Binding IconUrl}" />
            <Setter Property="ItemsSource" Value="{Binding SubMenuItems}" />
            <Setter Property="Command" Value="{Binding MenuItemClicked}" />
            <Setter Property="CommandParameter" Value="{Binding RelativeSource={RelativeSource Self}}" />
            <Setter Property="IconTemplate" >
                        <Image Source="{Binding}" Stretch="Fill"/>
    This Generates the menus just fine and they appear exactly as I expect HOWEVER the command does nothing ()i.e. the MENUCLICKED. I have set up the command MenuItemClicked in the ViewModel and correct instantiated it as an ICOMMAND but it never fires the command. What am I missing??. The command is set up as follows:
    public ICommand MenuItemClicked { get; set; }
    MenuItemClicked = new Command<RadMenuItem>(c =>
     I must have missed something but for the life of me I cannot see what. I know it is bound correctly as the menus are getting populated with the correct properties, icons and layouts.

    Please advise - thank you

  2. Rosen Vladimirov
    Rosen Vladimirov avatar
    640 posts

    Posted 30 Apr 2014 Link to this post

    Hello Hamish,

    You can find an example how to use Commands with RadMenuItems in our SDK Repository. You can use Telerik's DelegateCommand in order to execute a method directly in your ViewModel, for example:

    public ICommand MenuClickCommand { get; set; }
    this.MenuClickCommand = new DelegateCommand(OnMenuClickCommandExecuted);
    private void OnMenuClickCommandExecuted(object obj)
          // Command executed;

    Hope this helps.

    Rosen Vladimirov
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
Back to Top