问题
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>
回答1:
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>
回答2:
For these purposes I use TextDecorations property. For example in XAML:
<TextBlock Name="undelinedTextBlock"
TextDecorations="Underline"
Text="Underlined text"/>
In C#:
undelinedTextBlock.TextDecorations = TextDecorations.Underline;
See details here: https://msdn.microsoft.com/en-us/library/system.windows.controls.textblock.textdecorations(v=vs.105).aspx
来源:https://stackoverflow.com/questions/21664044/how-to-underline-text-with-different-color-in-wp8