How to remove Bottom Border Textbox | UWP

Anderson Rodrigues Cavalcante 291 Reputation points
2024-04-19T14:49:44.9933333+00:00

Hello.

I have a native TextBox and I'd like to remove this blue border-bottom in Light and Dark:

Focus State:

User's image User's image

Rest:
User's image User's image

I'd like to remove all these bottom borders.

However, if my SO is in High Contrast mode, I'd like to keep these native borders:
User's image

How to edit the TextBox style to keep only the borders in High Contrast?

Universal Windows Platform (UWP)
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,561 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
781 questions
0 comments No comments
{count} votes

Accepted answer
  1. Junjie Zhu - MSFT 16,391 Reputation points Microsoft Vendor
    2024-04-22T07:04:58.3366667+00:00

    Hi @Anderson Rodrigues Cavalcante ,

    Welcome to Microsoft Q&A!

    The default template of Textbox can be found in generic.xaml in: C:\Program Files (x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\{version}\Generic.

    Find the resource TextControlBorderBrushFocused and modify its value with a new SolidColorBrush.

    However, if my SO is in High Contrast mode, I'd like to keep these native borders

    In HighContrast mode, TextControlBorderBrushFocused"ResourceKey" still use default SystemControlHighlightAccentBrush.

    <TextBox Text="TextBox" >
        <TextBox.Resources>
            <ResourceDictionary>
                <ResourceDictionary.ThemeDictionaries>
                    <ResourceDictionary x:Key="Dark">
                        <SolidColorBrush x:Key="TextBorderTransparentBrush" Color="Red" />
                        <StaticResource x:Key="TextControlBorderBrushFocused" ResourceKey="TextBorderTransparentBrush" />
                    </ResourceDictionary>
                    <ResourceDictionary x:Key="Light">
                        <SolidColorBrush x:Key="TextBorderTransparentBrush" Color="Green" />
                        <StaticResource x:Key="TextControlBorderBrushFocused" ResourceKey="TextBorderTransparentBrush" />
                    </ResourceDictionary>
                    <ResourceDictionary x:Key="HighContrast">
                        <StaticResource x:Key="TextControlBorderBrushFocused" ResourceKey="SystemControlHighlightAccentBrush" />
                    </ResourceDictionary>
                </ResourceDictionary.ThemeDictionaries>
            </ResourceDictionary>
        </TextBox.Resources>
    </TextBox>
    

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful