有没有办法为我的自定义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继承。
答案 0 :(得分:3)
{Binding}
标记扩展名:
How can i change the default values of the Binding Option in WPF?
或创建自定义绑定类:
public class CustomBinding : Binding
{
public CustomBinding(string path)
:base(path)
{
this.NotifyOnValidationError = true;
}
}
用法:
<TextBlock Text="{local:CustomBinding Name}" />