Exemple #1
0
        private static void OnCommandChanged(EventToCommand element, DependencyPropertyChangedEventArgs e)
        {
            if (element == null)
            {
                return;
            }

            if (e.OldValue != null)
            {
#if NET45
                CanExecuteChangedEventManager.RemoveHandler((ICommand)e.OldValue, element.OnCommandCanExecuteChanged);
#else
                ((ICommand)e.OldValue).CanExecuteChanged -= element.OnCommandCanExecuteChanged;
#endif
            }

            var command = (ICommand)e.NewValue;
            if (command != null)
            {
#if NET45
                CanExecuteChangedEventManager.AddHandler(command, element.OnCommandCanExecuteChanged);
#else
                command.CanExecuteChanged += element.OnCommandCanExecuteChanged;
#endif
            }

            element.EnableDisableElement();
        }
Exemple #2
0
        protected virtual void OnCommandChanged(ICommand OldValue, ICommand NewValue)
        {
            if (onCommandUpdated == null)
            {
                onCommandUpdated = (o, e) => UpdateFromCommand();
            }

            if (OldValue != null)
            {
                CanExecuteChangedEventManager.RemoveHandler(OldValue, onCommandUpdated);
            }
            if (NewValue != null)
            {
                CanExecuteChangedEventManager.AddHandler(NewValue, onCommandUpdated);
            }
            onCommandUpdated(null, null);

            var oruc = OldValue as RoutedUICommand;
            var nruc = NewValue as RoutedUICommand;

            if (oruc != null && Equals(Header, oruc.Text))
            {
                this.ClearValue(HeaderProperty);
            }
            if (nruc != null && this.HasDefaultValue(HeaderProperty))
            {
                Header = nruc.Text;
            }
        }
Exemple #3
0
        private void UnhookCommand(ICommand command)
        {
#if RIBBON_IN_FRAMEWORK
            CanExecuteChangedEventManager.RemoveHandler(command, OnCanExecuteChanged);
#else
            if (_canExecuteChangedHandler != null)
            {
                command.CanExecuteChanged -= _canExecuteChangedHandler;
                _canExecuteChangedHandler  = null;
            }
#endif
            UpdateCanExecute();
        }
        private void UnhookCommand(ICommand command)
        {
#if NET4
            var handler = CommandHelpers.GetCanExecuteChangedHandler(this);
            if (handler != null)
            {
                command.CanExecuteChanged -= handler;
                CommandHelpers.SetCanExecuteChangedHandler(this, null);
            }
#else
            CanExecuteChangedEventManager.RemoveHandler(command, new EventHandler <EventArgs>(this.OnCanExecuteChanged));
#endif
            this.UpdateCanExecute();
        }
Exemple #5
0
        /// <summary>
        /// Called when the <see cref="Command"/> property changed.
        /// </summary>
        /// <param name="oldCommand">The old value.</param>
        /// <param name="newCommand">The new value.</param>
        protected virtual void OnCommandChanged(ICommand oldCommand, ICommand newCommand)
        {
            if (oldCommand != null)
            {
                CanExecuteChangedEventManager.RemoveHandler(oldCommand, OnCanExecuteChanged);
            }

            if (newCommand != null)
            {
                CanExecuteChangedEventManager.AddHandler(newCommand, OnCanExecuteChanged);
            }

            OnCanExecuteChanged();
        }
 private void UnhookCommand(ICommand command)
 {
     CanExecuteChangedEventManager.RemoveHandler(command, new EventHandler <EventArgs>(this.OnCanExecuteChanged));
     this.UpdateCanExecute();
 }
Exemple #7
0
 private void UnhookCommand(ICommand command)
 {
     CanExecuteChangedEventManager.RemoveHandler(command, OnCanExecuteChanged);
     UpdateCanExecute();
 }
 private void UnhookCommand(ICommand command)
 {
     Debug.Assert(command != null);
     CanExecuteChangedEventManager.RemoveHandler(command, OnCanExecuteChanged);
     UpdateCanExecute();
 }