Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>

Can anyone help?

like image 615
Matt H. Avatar asked Feb 26 '23 17:02

Matt H.


1 Answers

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>
like image 63
Quartermeister Avatar answered Mar 01 '23 07:03

Quartermeister