开发者

XAML: Refer to StaticResource in plain XAML? (without markup extension)

开发者 https://www.devze.com 2023-01-05 11:13 出处:网络
I am setting a validation rule on a series o开发者_运维技巧f textboxes. I\'d rather not create a new instance of my custom validation rule for each TextBox...

I am setting a validation rule on a series o开发者_运维技巧f 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>

Can anyone help?


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消