private static void CommandProperty_Changed(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { MenuItem element = dependencyObject as MenuItem; if (element != null) { MenuItemClickBehavior behavior = GetOrCreateBehavior(element); behavior.Command = e.NewValue as ICommand; } }
private static MenuItemClickBehavior GetOrCreateBehavior(MenuItem element) { MenuItemClickBehavior behavior = element.GetValue(MenuItemClickBehaviorProperty) as MenuItemClickBehavior; if (behavior == null) { behavior = new MenuItemClickBehavior(element); element.SetValue(MenuItemClickBehaviorProperty, behavior); } return(behavior); }
public static void SetMenuItemClickBehavior(DependencyObject obj, MenuItemClickBehavior value) { obj.SetValue(MenuItemClickBehaviorProperty, value); }