簡體   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