1

Is there a way to set ValidatesOnDataErrors to True for my custom DependencyProperty, so I do not have to do that every time I bind to it? Something in the lines of this.

public static readonly DependencyProperty TextProperty =
        DependencyProperty.Register(nameof(Text), typeof(string),
            typeof(ErrorTextEdit), new FrameworkPropertyMetadata(null)
            {
                BindsTwoWayByDefault = true,
                DefaultUpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                // Something Here maybe???
            });

    public string Text
    {
        get { return (string) GetValue(TextProperty); }
        set { SetValue(TextProperty, value); }
    }

My control could also inherit from TextBox if that can help.

Community
  • 1
  • 1
gajo357
  • 958
  • 12
  • 22

1 Answers1

3

No, I am afraid not. This is a property of the Binding class rather than of the dependency property. What you could to is to replace the {Binding} markup extension in your XAML markup with a custom markup extension that sets the ValidatesOnDataErrors property for you:

How can i change the default values of the Binding Option in WPF?

Or create a custom binding class:

public class CustomBinding : Binding
{
    public CustomBinding(string path)
        :base(path)
    {
        this.NotifyOnValidationError = true;
    }
}

Usage:

<TextBlock Text="{local:CustomBinding Name}" />
Community
  • 1
  • 1
mm8
  • 163,881
  • 10
  • 57
  • 88