0

I want to change the color of the Textbox header in 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. Thanks in advance!

geertjanknapen
  • 1,159
  • 8
  • 23
  • 3
    I think you will need to edit the Control template, use a simpler approach, or maybe even build your own UWP Custom Control – Tony Oct 22 '18 at 14:30
  • https://stackoverflow.com/questions/20585582/gtk-c-sharp-widget-change-color-not-working please check this page. I hope, it give idea to you. – Faruk Oct 22 '18 at 14:38

1 Answers1

0

For your requirement, you could custom TextBox's HeaderTemplate like the follow.

<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.

Update The foreground theme resource of HeaderContentPresenter is TextControlHeaderForeground you could also override it in app resource like the follow

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

Usage

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

enter image description here

Nico Zhu
  • 32,367
  • 2
  • 15
  • 36