WPF/MVVM - how to handle double-click on TreeViewItems in the ViewModel?

前端 未结 8 1897
刺人心
刺人心 2020-11-28 06:39

(Note - this is a re-post as my first question got posted under wrong headline: Here Sorry!)

I have a standard WPF treeview and have bound items to view model classe

8条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 07:19

    Meleak solution is great!, but i added check

        private static void OnMouseDoubleClick(object sender, RoutedEventArgs e)
        {
            Control control = sender as Control;
            ICommand command = (ICommand)control.GetValue(CommandProperty);
            object commandParameter = control.GetValue(CommandParameterProperty);
           //Check command can execute!!  
          if(command.CanExecute(commandParameter ))
             command.Execute(commandParameter);
        }
    

提交回复
热议问题