Take the 2-minute tour ×

I have a project in WPF 4 and VB.net. I need to change the color a single letter in a word in a label (the label's content changes quite a bit). I really am not sure if this is possible, but if it is, I'd appreciate help on figuring out how. TY!

share|improve this question
add comment

3 Answers

up vote 11 down vote accepted

Label is a content control so any type of content is permitted inside a label.You can easily do your requirement by something like

    <StackPanel Orientation="Horizontal">
        <TextBlock Foreground="Red" Text="T"/>
        <TextBlock Text="ext"/>
share|improve this answer
I'm looking to do something similar and I'm wondering if this technique will work and be bindable. For example highlighting all the uppercase letters in a dynamic string such as 'ThisIsMyTextBlock'. Would this be achievable using this approach? –  Ian May 2 '13 at 10:41
add comment

A cleaner way would be using the flow-content-capabilites of a TextBlock:

        <Run Text="L" Foreground="Green"/>
        <Run Text="orem Ipsum"/>

This limits binding a bit though, if that is needed.

share|improve this answer
This is a better solution if your text needs to wrap –  Damien McGivern Nov 2 '11 at 10:38
add comment

I just implemented something like this in our project, this will be static though - I'm not sure if that's what you need. You can change the content of the label as often as you need, but it will always have a red * at the end. I added a style to the project like this

<Style x:Key="RequiredFieldLabel"
       TargetType="{x:Type Label}">
  <Setter Property="ContentTemplate">
        <StackPanel Orientation="Horizontal">
          <TextBlock Text="{Binding}" />
          <TextBlock Text="*"
                   Foreground="red" />

Then you can use this style on a label anywhere in your project.

<Label Content="Enter Name:"
       Style="{StaticResource RequiredFieldLabel}" />
share|improve this answer
add comment

Your Answer


