【问题标题】:Change the textbox header color in C# UWP在 C# UWP 中更改文本框标题颜色
【发布时间】:2018-10-22 14:29:04
【问题描述】:

我想更改 UWP 中文本框标题的颜色。 我的文本框:

<TextBox x:Name="tbFullName" Header="Full Name" Margin="30,24,0,0" MaxLength="320" Width="400" HorizontalAlignment="Left" InputScope="PersonalFullName" VerticalAlignment="Stretch"/>

我当前(不工作)的代码来改变颜色:

tbFullName.Header = new SolidColorBrush(Windows.UI.Colors.White);

我希望有人能够提供帮助。 注意:我对 UWP 很陌生,对编程也很陌生,如果给我的答案不是太难理解,我将不胜感激。 提前致谢!

【问题讨论】:

  • 我认为您将需要编辑控件模板,使用更简单的方法,甚至可能构建自己的 UWP 自定义控件
  • stackoverflow.com/questions/20585582/… 请查看此页面。我希望它能给你一些想法。

标签: c# uwp


【解决方案1】:

根据您的要求,您可以自定义 TextBox 的 HeaderTemplate,如下所示。

<TextBox HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" FontSize="12" Header="Name" >
    <TextBox.HeaderTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding}" Foreground="Red" />
        </DataTemplate>
</TextBox.HeaderTemplate>

并修改DataTemplate中包含的TextBlock的Foreground。

更新 HeaderContentPresenter 的前台主题资源是 TextControlHeaderForeground 您也可以在应用资源中覆盖它,如下所示

 <Application.Resources>
    <SolidColorBrush x:Key="TextControlHeaderForeground" Color="Red" />
</Application.Resources>

用法

<TextBox Text="Cotent" Height="100" Header="Name"/>

【讨论】:

    猜你喜欢
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 2017-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多