How to customize the appearance of TextBox to underline?

qwecskcnjff1 41 Reputation points
2020-07-04T07:41:02.6+00:00

How to customize the appearance of TextBox to underline?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,691 questions
0 comments No comments
{count} votes

Accepted answer
  1. DaisyTian-1203 11,616 Reputation points
    2020-07-06T02:23:56.753+00:00

    There are two sample of custom the underline:

     <TextBox FontSize="35" Text="A" Foreground="Brown">  
                <TextBox.TextDecorations>  
                    <TextDecorationCollection>  
                        <TextDecoration PenOffset="1" PenOffsetUnit="Pixel" PenThicknessUnit="Pixel">  
                            <TextDecoration.Pen>  
                                <Pen Thickness="3" Brush="Green" />  
                            </TextDecoration.Pen>  
                        </TextDecoration>  
                        <TextDecoration PenOffset="2" />  
                    </TextDecorationCollection>  
                </TextBox.TextDecorations>  
            </TextBox>  
            <TextBox FontSize="32" Text="AAAA">  
                <TextBox.TextDecorations>  
                    <TextDecoration PenOffset="5" PenOffsetUnit="Pixel" PenThicknessUnit="Pixel">  
                        <TextDecoration.Pen>  
                            <Pen Thickness="4">  
                                <Pen.Brush>  
                                    <LinearGradientBrush Opacity="0.8" StartPoint="0,0.5"  EndPoint="1,0.5">  
                                        <LinearGradientBrush.GradientStops>  
                                            <GradientStop Color="Yellow" Offset="0" />  
                                            <GradientStop Color="Red" Offset="1" />  
                                        </LinearGradientBrush.GradientStops>  
                                    </LinearGradientBrush>  
                                </Pen.Brush>  
                                <Pen.DashStyle>  
                                    <DashStyle Dashes="1,2,3"/>  
                                </Pen.DashStyle>  
                            </Pen>  
                        </TextDecoration.Pen>  
                    </TextDecoration>  
                </TextBox.TextDecorations>  
            </TextBox>  
    

    Here is the result picture:
    11396-%E6%89%B9%E6%B3%A8-2020-07-06-102113.png


1 additional answer

Sort by: Most helpful
  1. Ken Tucker 5,846 Reputation points
    2020-07-04T23:39:25.543+00:00

    Set the textboxes TextDecoration to Underline

        <TextBox TextDecorations="Underline">Testing</TextBox>
    
    0 comments No comments