Command Binding MVVM

2 posts, 0 answers
  1. richard
    richard avatar
    4 posts
    Member since:
    Oct 2016

    Posted 31 Oct 2016 Link to this post


    i am trying to implement a command (LeftDoubleClick) from my view to viewmodel using mvvm pattern (without code behind and event).

    I saw some samples but they don't work for me!

    Please can someone tell me i i am making wrong?


    <telerik:RadGridView x:Name="radGridView" Margin="8" ItemsSource="{Binding Source={StaticResource DataSource}}"
       IsReadOnly="True"   >
                <MouseBinding Gesture="LeftDoubleClick" helpers:AttachedMouseBinding.Command="{Binding Path=DoubleClickCommand}" />



    public class UC_SEGridViewModel : InterfaceDescription.ViewModels.ViewModelBase
        private ViewModelMaster viewModelMaster;
        public ICommand DoubleClickCommand { get; set; }
        public UC_SEGridViewModel()
            DoubleClickCommand = new RelayCommand(GridItemDoubleClick);
        private void GridItemDoubleClick(object obj)
            //do something

    but i don't reach my callback method (GridItemDoubleClick) when i set a breackpoint

    the helper:

    public class AttachedMouseBinding
            const string PROPERTYNAMECOMMAND = "Command";
            public static readonly DependencyProperty CommandProperty = DependencyProperty.RegisterAttached(PROPERTYNAMECOMMAND, typeof(ICommand),
                typeof(AttachedMouseBinding), new FrameworkPropertyMetadata(CommandChanged));
            private static void CommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
                FrameworkElement fe = d as FrameworkElement;
                ICommand command = e.NewValue as ICommand;
                InputBinding inputBinding = new InputBinding(command, new MouseGesture(MouseAction.LeftDoubleClick));
                //if (inputBinding != null)
                //    inputBinding.Command = command;
            public static ICommand GetCommand(DependencyObject obj)
                return (ICommand)obj.GetValue(CommandProperty);
            public static void SetCommand(DependencyObject obj,ICommand value)
                obj.SetValue(CommandProperty, value);


    Thanks for your help,


  2. Ivan Ivanov
    Ivan Ivanov avatar
    1218 posts

    Posted 03 Nov 2016 Link to this post


    The InputBinding mechanism does not respect handled events. This is a common limitation to use it with custom controls. For example even the WPF TextBox, does not support them for much of the keyboard/mouse gestures, as it handles the respective events for navigation purposes. The case with RadGridView is just the same. It executes the logic for RowActivated at this point thus handling the event. If you want to have a no-code-behind solution for this scenario, you can use an attached behavior that is assigned in XAML, which has the event subscription in its body.

    Ivan Ivanov
    Telerik by Progress
    Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
Back to Top