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
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
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
BorderBrushworks, but that's only visible when the control loses focus. The setting of theUnderlineBrushhas no effect, it remains the standard validation error brush. I think this is because theValidation.HasErrortrigger 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
TargetNameis 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