XAML: access StaticResource in plain XAML? (without markup extension)

I set a validation rule for a number of text fields. I would prefer not to 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?

+3
source share
1 answer

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

<Binding.ValidationRules>
    <StaticResource ResourceKey="IsIntegerRule"/>
</Binding.ValidationRules>
+6
source

Source: https://habr.com/ru/post/1753014/


All Articles