[英]how to underline text with different color in WP8?
我有以下代碼:
<TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Style="{StaticResource PhoneTextTitle1Style}" FontSize="65">
<Underline Foreground="DeepSkyBlue">
<Run Foreground="Turquoise" Text="{Binding SomeProp}"></Run>
</Underline>
</TextBlock>
我需要的是用我的文字塗上綠松石色,並使用其他顏色 - “DeepSkyBlue”強調它。 我認為Run
元素應該覆蓋自己的父控件Foreground
屬性,但看起來它是錯誤的假設(實際上它覆蓋但我需要下划線以保持其他顏色)。 WP8有可能嗎? 如果是的話,我的樣品出了什么問題?
編輯:在Pantelis和aloisdg的幫助下,工作代碼如下所示:
<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>
我不確定這是最好的方法,但你可以使用border
。
<Border BorderBrush="DeepSkyBlue" BorderThickness="0,0,0,1">
<!-- your text -->
</Border>
出於這些目的,我使用TextDecorations屬性。 例如在XAML中:
<TextBlock Name="undelinedTextBlock"
TextDecorations="Underline"
Text="Underlined text"/>
在C#中:
undelinedTextBlock.TextDecorations = TextDecorations.Underline;
詳情請見: https : //msdn.microsoft.com/en-us/library/system.windows.controls.textblock.textdecorations(v=vs.105).aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.