C# 如何在WP8中为不同颜色的文本加下划线?
我有以下代码:C# 如何在WP8中为不同颜色的文本加下划线?,c#,xaml,windows-phone-8,windows-phone,C#,Xaml,Windows Phone 8,Windows Phone,我有以下代码: <TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Style="{StaticResource PhoneTextTitle1Style}" FontSize="65"> <Underline Foreground="DeepSkyBlue"> <Run Foreground="Turquoise" Text="{Binding SomePr
<TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Style="{StaticResource PhoneTextTitle1Style}" FontSize="65">
<Underline Foreground="DeepSkyBlue">
<Run Foreground="Turquoise" Text="{Binding SomeProp}"></Run>
</Underline>
</TextBlock>
我不确定这是最好的方法,但你可以使用一个
出于这些目的,我使用textEditions属性。 例如,在XAML中:
<TextBlock Name="undelinedTextBlock"
TextDecorations="Underline"
Text="Underlined text"/>
请参阅此处的详细信息:如果没有100%的把握,我认为这是不可能的。您可以使用stackpanel来表示textblock,并使用矩形、边框或任何其他适合情况的元素来绘制下划线。您的答案是正确的。使用Border+Grid解决了这个问题。请注意,该解决方案也适用于wp8.1 silverlight
<Border BorderBrush="DeepSkyBlue" BorderThickness="0,0,0,1">
<!-- your text -->
</Border>
<TextBlock Name="undelinedTextBlock"
TextDecorations="Underline"
Text="Underlined text"/>
undelinedTextBlock.TextDecorations = TextDecorations.Underline;