示例#1
0
        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;
            }
        }
示例#2
0
        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);
        }
示例#3
0
 public static void SetMenuItemClickBehavior(DependencyObject obj,
                                             MenuItemClickBehavior value)
 {
     obj.SetValue(MenuItemClickBehaviorProperty, value);
 }