We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
public class ValueControl : Control { public static readonly DependencyProperty ValueProperty = DependencyProperty.Register( "Value", typeof(int), typeof(ValueControl), new FrameworkPropertyMetadata( default(int), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, null, CoerceValue)); private bool isResetting; static ValueControl() { DefaultStyleKeyProperty.OverrideMetadata(typeof(ValueControl), new FrameworkPropertyMetadata(typeof(ValueControl))); EventManager.RegisterClassHandler(typeof(ValueControl), Validation.ErrorEvent, new EventHandler<ValidationErrorEventArgs>(OnError)); } public int Value { get { return (int)this.GetValue(ValueProperty); } set { this.SetValue(ValueProperty, value); } } private static object CoerceValue(DependencyObject d, object basevalue) { var control = (ValueControl)d; if (control.isResetting) { return control.GetValue(ValueProperty); } return basevalue; } private static void OnError(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) { var control = (ValueControl)sender; control.isResetting = true; BindingOperations.GetBindingExpressionBase(control, ValueProperty)?.UpdateTarget(); control.isResetting = false; } } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: