【问题标题】:How to design underlined custom textbox in UWP如何在 UWP 中设计带下划线的自定义文本框
【发布时间】:2021-09-19 13:28:42
【问题描述】:

如何在 UWP 中设计带下划线的自定义文本框。下面给出了此类文本框的示例-

【问题讨论】:

    标签: xaml uwp textbox uwp-xaml


    【解决方案1】:

    您可以设置BorderBrush="Purple"BorderThickness="0,0,0,2"直接改变边框颜色和边框粗细。

    如下:

    <TextBox Width="150" Height="40" BorderBrush="Purple" BorderThickness="0,0,0,2">
         <TextBox.Resources>
            <!-- To also have the focused TextBox only have a border at the bottom, 
                 we need to override this resource. -->
            <Thickness x:Key="TextControlBorderThemeThicknessFocused">0,0,0,2</Thickness>
        </TextBox.Resources>
    </TextBox>
    

    【讨论】:

    • 为什么不将 BorderThickness 设置为 0,0,0,1 呢?这样,您就不需要重新模板控件。
    • @chingucoding 是的,你说得对,这样更方便。
    • @chingucoding 将边框粗细设置为“0,0,0,1”的问题是当您选择文本框时,边框也会出现在左侧、顶部和右侧。
    • @RedwanDipto 这很好,您可以通过覆盖TextControlBorderThemeThicknessFocused 资源来更改它。我建议对提议的解决方案进行编辑,以将其包含在答案中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-09
    • 2012-01-10
    • 2011-04-22
    相关资源
    最近更新 更多