Esempio n. 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();
        }
Esempio n. 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;
            }
        }
Esempio n. 3
0
        private void HookCommand(ICommand command)
        {
#if RIBBON_IN_FRAMEWORK
            CanExecuteChangedEventManager.AddHandler(command, OnCanExecuteChanged);
#else
            _canExecuteChangedHandler  = new EventHandler(OnCanExecuteChanged);
            command.CanExecuteChanged += _canExecuteChangedHandler;
#endif
            UpdateCanExecute();
        }
Esempio n. 4
0
        private void HookCommand(ICommand command)
        {
#if NET4
            EventHandler handler = new EventHandler(OnCanExecuteChanged);
            CommandHelpers.SetCanExecuteChangedHandler(this, handler);
            command.CanExecuteChanged += handler;
#else
            CanExecuteChangedEventManager.AddHandler(command, new EventHandler <EventArgs>(this.OnCanExecuteChanged));
#endif
            this.UpdateCanExecute();
        }
Esempio n. 5
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();
        }
Esempio n. 6
0
        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();
        }
Esempio n. 7
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 HookCommand(ICommand command)
 {
     CanExecuteChangedEventManager.AddHandler(command, new EventHandler <EventArgs>(this.OnCanExecuteChanged));
     this.UpdateCanExecute();
 }
Esempio n. 9
0
 private void HookCommand(ICommand command)
 {
     CanExecuteChangedEventManager.AddHandler(command, OnCanExecuteChanged);
     UpdateCanExecute();
 }
Esempio n. 10
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();
 }