代码之家  ›  专栏  ›  技术社区  ›  Dmitry Streblechenko

UWP文本框中的下划线文本字体?

uwp
  •  3
  • Dmitry Streblechenko  · 技术社区  · 6 年前

    我正在将现有的Windows控件转换为UWP。在UWP的文本框控件中,我看不到有下划线字体样式的方法。

    我缺少一些基本的东西吗?或者我应该忘记TextBox而使用RichEditBox(这对我来说是一个巨大的过度杀戮)?

    谢谢您!

    2 回复  |  直到 6 年前
        1
  •  0
  •   Xie Steven    6 年前

    我缺少一些基本的东西吗?或者我应该忘记TextBox而使用RichEditBox(这对我来说是一个巨大的过度杀戮)?

    您可以使用 Windows.UI.Text.Core 命名空间来创建自己的自定义输入控件。

    您只需要使用一些通用的UWP控件(例如,textblock、stackpanel、border等)来创建一个输入控件(您可以称之为您自己的自定义文本框),当您在其中输入文本时,该控件带有下划线。

    这是UWP的官员 Custom Edit Control sample . 我只是指定了 TextDecorations 属性的属性值 TextBlock 在'CustomEditControl.xaml那么,我就达到了你的目标。

    <StackPanel x:Name="BorderPanel" BorderThickness="4" Background="White">
            <StackPanel x:Name="ContentPanel" Orientation="Horizontal" HorizontalAlignment="Left">
                <TextBlock x:Name="BeforeSelectionText" Foreground="Black" TextDecorations="Underline"/>
                <TextBlock x:Name="CaretText" Text="&#xe12b;" Foreground="Blue" FontFamily="Segoe UI Symbol"/>
                <Border Background="Blue">
                    <TextBlock x:Name="SelectionText" Foreground="White"/>
                </Border>
                <TextBlock x:Name="AfterSelectionText" Foreground="Black"/>
            </StackPanel>
    </StackPanel>
    

    enter image description here