private static void OnIntegerDependencyPropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { // Silently coerce the value back to >= 0 if negative. if (!(e.NewValue is int) || (int)e.NewValue < 0) { o.SetValue(e.Property, e.OldValue); } }