I have about 100 TextBoxes in a Form. I need to validate them if they are decimal for instance.
This works, but it is too verbose, I don’t want to have 800 in place of 100 rows in XAML.
<TextBox.Text>
<Binding Path="MyPath" UpdateSourceTrigger="PropertyChanged" Stringformat="{}{0:N}" NotifyOnValidationError="True">
<Binding.ValidationRules>
<myRulesNamespace:MyValidationRule ValidationType="decimal" />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
Is there any way how to rewrite it to the short form like this? :
Text="{Binding MyPath, UpdateSourceTrigger='PropertyChanged', StringFormat='{}{0:N}', NotifyOnValidationError=True, ValidationRules NOW WHAT?}"
Short answer: You cannot. The Validation-rules property is a collection, and there is currently no way to write these in the Binding shorthand.
You can however create a class inheriting from Binding, like this:
And then use that instead of the normal Binding tag.