I have a UserControl
that contains other controls and a TextBox
. It has a Value
property that is bound to the TextBox
text and has ValidatesOnDataErrors
set to True.
When a validation error occurs in the Value
property binding, the error template (standard red border) is shown around the entire UserControl
.
Is there a way to show it around the TextBox
only?
I'd like to be able to use any error template so simply putting border around textbox and binding its color or something to Validation.HasError
is not an option.
Here's my code:
<DataTemplate x:Key="TextFieldDataTemplate">
<c:TextField DisplayName="{Binding Name}" Value="{Binding Value, Mode=TwoWay, ValidatesOnDataErrors=True}"/>
</DataTemplate>
<controls:FieldBase x:Name="root">
<DockPanel DataContext="{Binding ElementName=root}">
<TextBlock Text="{Binding DisplayName}"/>
<TextBox x:Name="txtBox"
Text="{Binding Value, Mode=TwoWay, ValidatesOnDataErrors=True}"
IsReadOnly="{Binding IsReadOnly}"/>
</DockPanel>
UserControl (FieldBase) is than bound to ModelView which performs validation.