private static void OnSetCommandParameterCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { TreeView menuItem = dependencyObject as TreeView; if (menuItem != null) { TreeViewCommandBehavior behavior = GetOrCreateBehavior(menuItem); behavior.CommandParameter = e.NewValue; } }
private static TreeViewCommandBehavior GetOrCreateBehavior(TreeView menuItem) { TreeViewCommandBehavior behavior = menuItem.GetValue(SelectedCommandBehaviorProperty) as TreeViewCommandBehavior; if (behavior == null) { behavior = new TreeViewCommandBehavior(menuItem); menuItem.SetValue(SelectedCommandBehaviorProperty, behavior); } return(behavior); }