Wpf XAML:参考普通XAML中的StaticResource?(不带标记扩展)
我正在对一系列文本框设置验证规则。我不希望为每个文本框创建自定义验证规则的新实例Wpf XAML:参考普通XAML中的StaticResource?(不带标记扩展),wpf,vb.net,data-binding,xaml,validation,Wpf,Vb.net,Data Binding,Xaml,Validation,我正在对一系列文本框设置验证规则。我不希望为每个文本框创建自定义验证规则的新实例 <Window.Resources> <my:IsIntegerRule x:Key="IsIntegerRule"/> </Window.Resources> ... ... <TextBox> <TextBox.Text> <Binding XPath="@num" UpdateSourceTrigger="Prope
<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>
...
...
有人能帮忙吗?您可以对标记扩展使用普通的属性元素语法。看见看起来是这样的:
<Binding.ValidationRules>
<StaticResource ResourceKey="IsIntegerRule"/>
</Binding.ValidationRules>
谢谢@Quartermeister,一旦我把它放在我的代码中,我在XAML编辑器中得到一个错误,说类型无效。然而,它的工作就像魅力。