Пример #1
0
        /// <summary>
        /// Called when [set command callback].
        /// </summary>
        /// <param name="dependencyObject">The dependency object.</param>
        /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void OnSetCommandCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
        {
            MenuItem element = dependencyObject as MenuItem;

            if (element != null)
            {
                ClickBehavior behavior = GetOrCreateBehavior(element);
                behavior.Command = e.NewValue as ICommand;
            }
        }
Пример #2
0
        /// <summary>
        /// Gets the or create behavior.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns></returns>
        private static ClickBehavior GetOrCreateBehavior(MenuItem element)
        {
            ClickBehavior behavior = element.GetValue(ItemClickCommandBehaviorProperty) as ClickBehavior;

            if (behavior == null)
            {
                behavior = new ClickBehavior(element);
                element.SetValue(ItemClickCommandBehaviorProperty, behavior);
            }

            return(behavior);
        }
Пример #3
0
 /// <summary>
 /// Sets the item click command behavior.
 /// </summary>
 /// <param name="obj">The obj.</param>
 /// <param name="value">The value.</param>
 public static void SetItemClickCommandBehavior(DependencyObject obj, ClickBehavior value)
 {
     obj.SetValue(ItemClickCommandBehaviorProperty, value);
 }