我正在设置一系列文本框的验证规则.我宁愿不为每个TextBox创建一个新的自定义验证规则实例…… Window.Resources my:IsIntegerRule x:Key="IsIntegerRule"//Window.Resources......TextBox TextBox.Text Binding XPa
<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>
有人可以帮忙吗?
您可以使用常规属性元素语法进行标记扩展.见 Markup Extensions and WPF XAML.它看起来像这样:<Binding.ValidationRules>
<StaticResource ResourceKey="IsIntegerRule"/>
</Binding.ValidationRules>
