AbsoluteSith
AbsoluteSith

Reputation: 1967

How to style TextBox headers with multiple colors in Xaml UWP?

I have a lot of textboxes (100's) and I want to style them such that a part of the textbox is certain color and the other in certain.

enter image description here

The above image states what I need. The asterisk to be Red in color.

I have achieved this by using this code

<TextBox.Header>
    <TextBlock >
        <Run >Card Number</Run><Run Foreground="Red">*</Run>
    </TextBlock>
</TextBox.Header> 

But I have too many textboxes can I write a style to achieve this? As the content of the header is dynamic I was wondering how can I do this?

Upvotes: 0

Views: 811

Answers (1)

AbsoluteSith
AbsoluteSith

Reputation: 1967

Alright achieved this by creating the below styling.

<Style x:Key="mandatoryTextBox" TargetType="TextBox">
    <Setter Property="HeaderTemplate">
        <Setter.Value>
            <DataTemplate>
                <TextBlock>
                     <Run Text="{Binding}"></Run><Run Foreground="Red">*</Run>
                </TextBlock>
            </DataTemplate>
        </Setter.Value>
    </Setter>
</Style>

Upvotes: 1

Related Questions