У меня есть ViewModel IDataErrorInfo
У меня есть свойство с аннотацией данных:
[Required(ErrorMessage = "Login field should be filled in")]
[RegularExpression(@"\w+(@)[a-zA-z]+(\.)[a-zA-z]+", ErrorMessage = ("Use the right email format"))]
public string Email
{
get => authRequstModel.Email;
set => Set(ref authRequstModel.Email, value);
}
В XAML у меня есть текстовое поле:
<TextBox x:Name="email" Style="{StaticResource emaliStyle}" Grid.Column="2" Grid.Row="2">
<TextBox.Text>
<Binding Mode="TwoWay" Path="Email" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<DataErrorValidationRule ValidatesOnTargetUpdated="False"/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
Сресурс:
<Style TargetType="TextBox" x:Key="emaliStyle">
<Setter Property="Width" Value="204"/>
<Setter Property="Height" Value="30"/>
<Setter Property="FontSize" Value="18"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="FontSize" Value="20"/>
<Setter Property="Padding" Value="5,2,1,0"/>
<Setter Property="SelectionBrush" Value="Red"/>
<Setter x:Name="LoginValidation" Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<DockPanel LastChildFill="True">
<TextBlock DockPanel.Dock="Bottom" Foreground="Maroon" FontSize="8pt"
Text="{Binding ElementName=email, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">
</TextBlock>
<Border BorderBrush="DarkRed" BorderThickness="2" CornerRadius="10">
<AdornedElementPlaceholder Name="email" />
</Border>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Если он недействителен, он помечен красным, но как пометить его зеленым, если он действителен?