Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It appears that you don't have the event handler in the second view (and this is why it's not recommended to use the code behind).</p> <p>I know you said that the TreeView does not have the Double Click Command but that can't stop us from creating one for ourselves.</p> <p>Here's a basic class I wrote to expose a DoubleClickCommand to any Framework element</p> <pre><code> public class DoubleClickCommand { public static object GetDoubleClickParameter(DependencyObject obj) { return (object)obj.GetValue(DoubleClickParameterProperty); } public static void SetDoubleClickParameter(DependencyObject obj, object value) { obj.SetValue(DoubleClickParameterProperty, value); } public static ICommand GetDoubleClickCommand(DependencyObject obj) { return (ICommand)obj.GetValue(DoubleClickCommandProperty); } public static void SetDoubleClickCommand(DependencyObject obj, ICommand value) { obj.SetValue(DoubleClickCommandProperty, value); } public static readonly DependencyProperty DoubleClickParameterProperty = DependencyProperty.RegisterAttached("DoubleClickParameter", typeof(object), typeof(DoubleClickCommand), new UIPropertyMetadata(null)); public static readonly DependencyProperty DoubleClickCommandProperty = DependencyProperty.RegisterAttached("DoubleClickCommand", typeof(ICommand), typeof(DoubleClickCommand), new UIPropertyMetadata(null, OnDoubleClickCommandChanged)); private static void OnDoubleClickCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs args) { FrameworkElement elem = d as FrameworkElement; var newCommand = args.NewValue as ICommand; if (elem != null) { if (newCommand != null) { elem.MouseLeftButtonDown += elem_MouseLeftButtonDown; } else { elem.MouseLeftButtonDown -= elem_MouseLeftButtonDown; } } } private static void elem_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { if (e.ClickCount &gt; 1) { DependencyObject dep = sender as DependencyObject; ICommand command = GetDoubleClickCommand(dep) as ICommand; var parameter = GetDoubleClickParameter(dep); if (command != null) { if (command.CanExecute(parameter)) { command.Execute(parameter); } } } } } </code></pre> <p>To use it for your TreeViewItems, just set the Command and CommandParameter(optional) on your TreeView's ItemTemplate.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload