Beispiel #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();
        }
Beispiel #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;
            }
        }
Beispiel #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();
        }
Beispiel #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();
        }
Beispiel #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 HookCommand(ICommand command)
 {
     CanExecuteChangedEventManager.AddHandler(command, new EventHandler <EventArgs>(this.OnCanExecuteChanged));
     this.UpdateCanExecute();
 }
Beispiel #7
0
 private void HookCommand(ICommand command)
 {
     CanExecuteChangedEventManager.AddHandler(command, OnCanExecuteChanged);
     UpdateCanExecute();
 }