Ghost1372

everything can be handy

Validation Rule

Rules

Name Remarks
NoBlankTextRule Property: ErrorContent
RegexRule Property: ErrorContent, Type, Pattern

How to Create ValidationRule?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public class NumericUpDownDemoRule : ValidationRule
{
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
if (value is not double doubleValue)
{
return new ValidationResult(false, HandyControl.Properties.Langs.Lang.FormatError);
}

return doubleValue % 2 > double.Epsilon
? new ValidationResult(false, Properties.Langs.Lang.Error)
: ValidationResult.ValidResult;
}
}

Example

RegexRule

1
2
3
4
5
6
7
8
9
 <hc:SearchBar hc:InfoElement.Placeholder="Please Enter Email" hc:InfoElement.Title="Title" Margin="0,32,0,0" hc:InfoElement.Necessary="True" Style="{StaticResource SearchBarPlus}">
<hc:SearchBar.Text>
<Binding Path="Email1" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<hc:RegexRule Type="Mail"/>
</Binding.ValidationRules>
</Binding>
</hc:SearchBar.Text>
</hc:SearchBar>

NoBlankTextRule

1
2
3
4
5
6
7
8
9
 <hc:SearchBar Style="{StaticResource SearchBarPlus}">
<hc:SearchBar.Text>
<Binding Path="Email1" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<hc:NoBlankTextRule/>
</Binding.ValidationRules>
</Binding>
</hc:SearchBar.Text>
</hc:SearchBar>
0%