/// <summary> /// Handles changes to the Event property. /// </summary> /// <param name="dependencyObject">The dependency object.</param> /// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param> private static void OnEventChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { CommandBehaviorBinding binding = FetchOrCreateBinding(dependencyObject); // Check if the Event is set. If yes we need to rebind the Command to the new event and unregister the old one if (binding.Event != null && binding.Owner != null) { binding.Dispose(); } // Bind the new event to the command if (e.NewValue != null && !string.IsNullOrEmpty(e.NewValue.ToString())) { binding.BindEvent(dependencyObject, e.NewValue.ToString()); } }