简体   繁体   English

在C#UWP中更改文本框标题颜色

[英]Change the textbox header color in C# UWP

I want to change the color of the Textbox header in UWP. 我想在UWP中更改文本框标题的颜色。 My Textbox: 我的文字框:

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

My current (not working) code to change the color: 我当前(无效)的代码来更改颜色:

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

I hope someone is able to help. 我希望有人能够提供帮助。 Note: I'm am very new to UWP and I'm quite new to programming, I would really appreciate if the answers given to me aren't all too hard to understand. 注意:我对UWP还是很陌生,对编程也很陌生,如果给我的答案不是很难理解,我将不胜感激。 Thanks in advance! 提前致谢!

For your requirement, you could custom TextBox's HeaderTemplate like the follow. 根据您的要求,您可以像下面这样自定义TextBox的HeaderTemplate

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

And modify the Foreground the for TextBlock that contained in DataTemplate. 并修改DataTemplate中包含的TextBlock的Foreground。

Update The foreground theme resource of HeaderContentPresenter is TextControlHeaderForeground you could also override it in app resource like the follow 更新 HeaderContentPresenter的前台主题资源是TextControlHeaderForeground您也可以在应用程序资源中覆盖它,如下所示

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

Usage 用法

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

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM