在我的WPF应用程序,我想设置 NotifyOnValidationError
到真
(框架默认为false)的如果它们具有连接到结合任何ValidationRules所有子控件/绑定。事实上,这将是很好指定其他具有约束力的默认太 - 例如, ValidatesOnDataErrors
也应该永远是正确的。
例如,在下面的文本框中,我不希望有手动指定NotifyOnValidationError属性。
<文本框>
< TextBox.Text>
<绑定路径=邮政code
ValidatesOnDataErrors =真
NotifyOnValidationError =真>
< Binding.ValidationRules>
<规则:邮政codeRule />
< /Binding.ValidationRules>
< /装订>
< /TextBox.Text>
< /文本框>
![WPF数据绑定](https://p.xsw88.cn/allimgs/daicuo/20230903/5308.png)
解决方案
由于绑定
只是一个的标记扩展你可以创建一个自定义的标记扩展扩展绑定
,并设置这些属性到所需的默认值。
In my WPF application, I want to set NotifyOnValidationError
to true
(the framework defaults it to false) for all child controls/bindings if they have any ValidationRules attached to the binding. Indeed, it would be nice to specify other binding defaults too - e.g. ValidatesOnDataErrors
should also always be true.
For example, in the following text box I don't want to have to manually specify the NotifyOnValidationError property.
<TextBox>
<TextBox.Text>
<Binding Path="PostalCode"
ValidatesOnDataErrors="True"
NotifyOnValidationError="True">
<Binding.ValidationRules>
<rules:PostalCodeRule />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
解决方案
Since Binding
is just a markup extension you could create a custom Markup Extensions that extends Binding
and sets those properties to your desired defaults.
相关推荐
最新文章