private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { // Note: This callback only purpose is to validate the value change. // The value change is not acceptable if one the the two conditions // below is met : // 1 - the new value is DependencyProperty.UnsetValue. // 2 - the setter is sealed. // We reset the value to the old value and throw an exception if one // of these conditions is verified. Setter setter = (Setter)d; if (setter._throwOnNextValueChange) { setter._throwOnNextValueChange = false; setter.CheckSealed(); throw new InvalidOperationException("Cannot unset a Setter value."); } if (setter.IsSealed || e.NewValue == DependencyProperty.UnsetValue) { setter._throwOnNextValueChange = true; setter.Value = e.OldValue; } }