Is it possible to override the background colour of the Underline control on validation error? #3469
Unanswered
LeeDawsonUK
asked this question in
Q&A
Replies: 1 comment
-
@LeeDawsonUK Not tested, but off the top of my head I would say you could simply hijack the resource (key) for that <Style x:Key="MyMaterialDesignTextBox" BasedOn="{StaticResource MaterialDesignTextBox}" TargetType="{x:Type TextBox}">
<Style.Resources>
<SolidColorBrush x:Key="MaterialDesign.Brush.ValidationError" Color="Orange" po:Freeze="True" />
</Style.Resources>
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="BorderBrush" Value="Orange" />
</Trigger>
</Style.Triggers>
</Style> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to override the colour of a TextBox's Underline when there is a validation error on the control. The use case here is that our application has different severities of validation error and we want to display some in red and some in a less serious amber.
This is what I have tried:
The setting of the
BorderBrush
works, but that's only visible when the control loses focus. The setting of theUnderlineBrush
has no effect, it remains the standard validation error brush. I think this is because theValidation.HasError
trigger has hard-codedMaterialDesign.Brush.ValidationError
(i.e. the UnderlineBrush is irrelevant in this scenario):I cannot override this in a derived Style because referencing elements in the template via
TargetName
is not allowed on a Style setter.Is what I'm trying to do here possible without making my own copy of the TextBox template?
Beta Was this translation helpful? Give feedback.
All reactions