I have ValidationRule by using System.Windows.Controls and that rule return some custom message. But the font size is too small and how can I change the font size?
Screenshot...Textbox content and error content of validation result
Here is example code of WPF Window App...
public class NotEmptyValidationRule : ValidationRule
{
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
if(value != null)
return string.IsNullOrWhiteSpace((value ?? "").ToString())
? new ValidationResult(false, "Field is required")
: ValidationResult.ValidResult;
return ValidationResult.ValidResult;
}
}
Here is XAML... (Note: Changing Fontsize at TextBox tag didn't work)
<Page...
<TextBox
x:Name="txtName"
Grid.Row="1"
Grid.Column="1"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Width="210"
Margin="5,0,0,0"
FontSize="14"
Style="{StaticResource MaterialDesignTextBox}">
<TextBox.Text>
<Binding Path="RCName" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<local2:NotEmptyValidationRule ValidatesOnTargetUpdated="True"/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
</Page>
For your requirement, you need to modify the
Validation.ErrorTemplate. Since you are using MeterialDesign, you can either write your modified style forTextBox, based on existing style or only write modified ErrorTemplate and apply it directly to TextBox usingValidation.ErrorTemplateproperty.the style for TextBox ErrorTemplate has been copied from here