有没有办法指定自定义依赖项 属性 的默认 ValidatesOnDataErrors?

Is there a way to specify a custom dependency property's default ValidatesOnDataErrors?

有没有办法为我的自定义 DependencyProperty 将 ValidatesOnDataErrors 设置为 True,这样我就不必在每次绑定到它时都这样做? 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); }
    }

如果有帮助,我的控件也可以从 TextBox 继承。

不,恐怕不是。这是绑定 class 而不是依赖项 属性 的 属性。您可以将 XAML 标记中的 {Binding} 标记扩展替换为自定义标记扩展,为您设置 ValidatesOnDataErrors 属性:

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

或者创建自定义绑定class:

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

用法:

<TextBlock Text="{local:CustomBinding Name}" />