Search code examples
c#wpfxamlcontroltemplatematerial-design-in-xaml

Editing templates from MaterialDesignInXaml


I am attempting to use the materialDesignInXaml StaticResource MaterialDesignOutlinedTextBox. I have an issue where say, I want an not selected textBox to be Blue, and when i select the textbox, it appears to turn green.

From comment below, i was able to get the selected textbox border brush to turn green using, materialDesign:TextFieldAssist.UnderlineBrush. However, i do not know how to control the borderbrush color when it is unselected to turn to blue. Default is black but I am unable to figure out where this color is set.


Solution

  • There are two different brushes involved. One is used for the underline color on hovering and the other is used in case the value is proved invalid through validation. The normal underline can be changed through the TextFieldAssist.UnderlineBrush attached property on the TextBox.

    <TextBox materialDesign:TextFieldAssist.UnderlineBrush="Green">
    

    The validation brush called MaterialDesignValidationErrorBrush (red by default) is referenced in the control template for TextBox using a DynamicResource, so you can override it in the local resources (or application if you want) without needing to copy or change the control template.

    <TextBox>
       <TextBox.Resources>
          <SolidColorBrush x:Key="MaterialDesignValidationErrorBrush" Color="Green"/>
       </TextBox.Resources>
       <!-- ...other markup. -->
    </TextBox>