Search code examples
c#wpfmaterial-designunderline

MaterialDesign Underline Color Of TextBox in Wpf


I have more than one TextBox. I want to change the underlines depending on special circumstances. I'm using the MaterialDesign style. I want to change the underline of the TextBox. It's a feasible situation in XAML, but how can I do it in code-behind? TextboxName.Underline cannot be found.

My xaml code

<TextBox x:Name="Pulse2" Style="{StaticResource MaterialDesignFloatingHintTextBox}" VerticalAlignment="Top" HorizontalAlignment="Left"
         Foreground="{Binding Foreground, ElementName=CardID}" Height="43" Width="132" IsReadOnly="True"
         materialDesign:TextFieldAssist.UnderlineBrush="{Binding Background, ElementName=HaltButton}"
         materialDesign:HintAssist.Foreground="#244886"
         AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto"
         materialDesign:HintAssist.Hint="Pulse2" Margin="281,136,0,0"/>

Not Found

Pulse.Underline !!!

Solution

  • You can use the setter for the UnderlineBrush property on TextFieldAssist to set any Brush e.g.:

    TextFieldAssist.SetUnderlineBrush(Pulse2, Brushes.Black);