Search code examples
c#xamlwindows-phone-8windows-phone

how to underline text with different color in WP8?


I have the following code:

 <TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Style="{StaticResource PhoneTextTitle1Style}" FontSize="65">
       <Underline Foreground="DeepSkyBlue">
            <Run Foreground="Turquoise" Text="{Binding SomeProp}"></Run>
       </Underline>
 </TextBlock>

What I need is to paint in turquoise color my text and underline it using other color - "DeepSkyBlue". I thought Run element should overwrite the parent control Foreground property for itself but it looks like it was wrong assumption (actually it overwrites but I need underline to stay other color). Is it possible in WP8? If yes, what is wrong with my sample?

EDIT: with the help of the Pantelis and aloisdg the working code looks like this:

        <Grid Margin="0,0,0,10" HorizontalAlignment="Center">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
            </Grid.ColumnDefinitions>

            <Border BorderBrush="DeepSkyBlue" BorderThickness="0,0,0,1">
                <TextBlock TextWrapping="Wrap" Style="{StaticResource PhoneTextTitle1Style}" FontSize="65">
                    <Run Foreground="Turquoise" Text="{Binding SomeProp}"></Run>
                </TextBlock>
            </Border>
        </Grid>

Solution

  • I am not sure this is the best way to do it, but you can use a border.

    <Border BorderBrush="DeepSkyBlue" BorderThickness="0,0,0,1">
        <!-- your text -->
    </Border>