Hi
I created a validator for checking if a value is a correct IBAN. I am trying to follow the pattern explained here:
https://help.syncfusion.com/wpf/maskedtextbox/validation
My validator makes use of a nuget package IbanNet. This is what the validator looks like.
public class SfMaskedEditIBANValidator : ValidationRule
{
public override System.Windows.Controls.ValidationResult Validate(object value, CultureInfo cultureInfo)
{
IIbanValidator _ibanValidator = new IbanValidator();
IbanNet.ValidationResult result = _ibanValidator.Validate(value.ToString());
System.Windows.Controls.ValidationResult output = new(result.IsValid, result.Error);
return output;
}
}
I added the correct namespace of the validator to my xaml document. The example suggest that I need to define in xaml:
<Trigger Property="ValidationMode" Value="KeyPress">
<Setter Property="Text">
<Setter.Value>
<Binding Path="Value" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<local:NameValidator/>
</Binding.ValidationRules>
</Binding>
</Setter.Value>
</Setter>
</Trigger>
So I have tried the following (see below). Not that I had to place this code inside <Style TargetType="sf:SfMaskedEdit"> <Style.Triggers>, otherwise I could not place
<Trigger Property="ValidationMode" Value="KeyPress"> on the control.
My SfMaskedEditIBANValidator is not executed when I enter an IBAN value in the maskededit control. I am unsure what I am doing wrong.
Any help would be appreciated.
Kind regards,
Niels van Strien
<sf:SfTextInputLayout
x:Name="BankAccountNumber"
Grid.Row="9"
Grid.Column="3"
Margin="0 0 0 0"
Hint="IBAN nummer">
<sf:SfMaskedEdit
x:Name="IBANME"
Foreground="{Binding ElementName=BankAccountNumber, Path=Foreground, Mode=TwoWay}"
Mask=">LL00 >LLLL 0000 0000 00"
MaskType="Simple"
Value="{Binding Path=IBAN, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
ErrorBorderBrush="Red"
ValidationMode="KeyPress">
<sf:SfMaskedEdit.Style>
<Style TargetType="sf:SfMaskedEdit">
<Style.Triggers>
<Trigger Property="ValidationMode" Value="KeyPress">
<Setter Property="Text">
<Setter.Value>
<Binding Path="Value" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<validators:SfMaskedEditIBANValidator/>
</Binding.ValidationRules>
</Binding>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</sf:SfMaskedEdit.Style>
</sf:SfMaskedEdit>
</sf:SfTextInputLayout>