static void UpdateObservedIsPresent(ButtonBase b) { if (b != null) { b.SetCurrentValue(IsPressedProperty, b.IsPressed); } }
static void Command_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e) { ButtonBase buttonBase = (ButtonBase)d; if (e.OldValue != null && e.NewValue == null) { buttonBase.Click -= ExecuteCommand; } if (e.OldValue == null && e.NewValue != null) { buttonBase.Click += ExecuteCommand; } // Set IsEnabled value depending on CanExecute if (buttonBase.Command != null) { buttonBase.SetCurrentValue(IsEnabledProperty, buttonBase.IsEnabled && buttonBase.Command.CanExecute(buttonBase.CommandParameter)); } }