예제 #1
0
        /// <summary>
        /// Sets the value of the CommandToCommand.Bindings attached property to a given System.Windows.UIElement.
        /// </summary>
        /// <param name="uiElement">The element on which to set the attached property.</param>
        /// <param name="value">The property value to set.</param>
        public static void SetBindings(UIElement uiElement, CommandToCommandBindingCollection value)
        {
            if (uiElement == null)
            {
                throw new ArgumentNullException(nameof(uiElement));
            }

            var bindings = (CommandToCommandBindingCollection)uiElement.GetValue(BindingsProperty);

            bindings?.Unhook();

            uiElement.SetValue(BindingsProperty, value);
        }
예제 #2
0
        /// <summary>
        /// Gets the value of the CommandToCommand.Bindings attached property from a given System.Windows.UIElement.
        /// </summary>
        /// <param name="uiElement">The element from which to read the property value.</param>
        /// <returns>The value of the CommandToCommand.Bindings attached property.</returns>
        public static CommandToCommandBindingCollection GetBindings(UIElement uiElement)
        {
            if (uiElement == null)
            {
                throw new ArgumentNullException(nameof(uiElement));
            }

            var bindings = (CommandToCommandBindingCollection)uiElement.GetValue(BindingsProperty);

            if (bindings == null)
            {
                bindings = new CommandToCommandBindingCollection(uiElement);
                uiElement.SetValue(BindingsProperty, bindings);
            }

            return(bindings);
        }