Reputation: 1967
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.
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
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