XAML:请参考简单XAML中的StaticResource? (无标记扩展名) [英] XAML: Refer to StaticResource in plain XAML? (without markup extension)

查看:524
本文介绍了XAML:请参考简单XAML中的StaticResource? (无标记扩展名)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一系列文本框中设置验证规则。我宁愿不为每个TextBox创建一个新的自定义验证规则实例...

I am setting a validation rule on a series of textboxes. I'd rather not create a new instance of my custom validation rule for each 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>

任何人都可以帮忙?

推荐答案

您可以使用标准属性元素语法进行标记扩展。请参阅标记扩展和WPF XAML 。看起来像这样:

You can use the normal property element syntax for markup extensions. See Markup Extensions and WPF XAML. It looks like this:

<Binding.ValidationRules>
    <StaticResource ResourceKey="IsIntegerRule"/>
</Binding.ValidationRules>

这篇关于XAML:请参考简单XAML中的StaticResource? (无标记扩展名)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆