我正在为一系列文本框设置验证规则。我宁愿不为每个TextBox创建一个新的自定义验证规则实例......
<Window.Resources>
<my:IsIntegerRule x:Key="IsIntegerRule"/>
</Window.Resources>
...
...
<TextBox>
<TextBox.Text>
<Binding XPath="@num" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<-- WHAT IS THE EQUIVALENT OF WRITING: {StaticResource IsIntegerRule} here -->
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
有人可以帮忙吗?
答案 0 :(得分:7)
您可以使用标准扩展的常规属性元素语法。见Markup Extensions and WPF XAML。它看起来像这样:
<Binding.ValidationRules>
<StaticResource ResourceKey="IsIntegerRule"/>
</Binding.ValidationRules>