繁体   English   中英

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

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

我想在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还是很陌生,对编程也很陌生,如果给我的答案不是很难理解,我将不胜感激。 提前致谢!

根据您的要求,您可以像下面这样自定义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"/>

在此处输入图片说明

暂无
暂无

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

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