[WPF][C#] Validation Rule avec Binding
Bonjour,
Je souhaite crée une ValidationRule dont les paramètres sont Bindés, comme ceci :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| <local:MinMaxValidationRule
Minimum="{Binding RelativeSource={
RelativeSource FindAncestor,
AncestorType=local:IntegerTextBox,
AncestorLevel=1},
Path=Min}"
Maximum="{Binding RelativeSource={
RelativeSource FindAncestor,
AncestorType=local:IntegerTextBox,
AncestorLevel=1},
Path=Max}"/>
</local:MinMaxValidationRule> |
Ce morceaux de code est placé dans le style d'un control personnalisé nommé "IntegerTextBox".
je souhaite donc utiliser ma nouvelle Textbox comme ceci:
Code:
<my:IntegerTextBox [...] Min="12" Max="27"/>
Mais étant donné qu'une validation rule ne dépent pas de Dependancy object, je ne peut pas crée de dependancy property (propdp) et donc je ne peut pas effectué le binding ci-dessus.
j'ai donc créé une classe dérivée de Dependancy object que j'ai instancié dans MinMaxValidationRule , puis j'ai effectué le binding sur les propdp de cette instance:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <local:MinMaxValidationRule>
<local:MinMaxValidationRule.ValidRange>
<local:Int64RangeChecker
Minimum="{Binding RelativeSource={
RelativeSource FindAncestor,
AncestorType=local:IntegerTextBox,
AncestorLevel=1},
Path=Min}"
Maximum="{Binding RelativeSource={
RelativeSource FindAncestor,
AncestorType=local:IntegerTextBox,
AncestorLevel=1},
Path=Max}"/>
</local:MinMaxValidationRule.ValidRange>
</local:MinMaxValidationRule> |
mais mon binding ne marche pas.
Pourquoi ne pourrais-je pas récupérer les valeurs définies dans ma TextBox ?
[EDIT] A savoir que lorsque je met les valeurs en dur directement dans ma Validation Rule (pour le test car ce n'est pas le comportement recherché) ça marche :
Code:
1 2 3 4 5 6 7
| <local:MinMaxValidationRule>
<local:MinMaxValidationRule.ValidRange>
<local:Int64RangeChecker
Minimum="12"
Maximum="25"/>
</local:MinMaxValidationRule.ValidRange>
</local:MinMaxValidationRule> |
merci d'avance,