我试图回答一个问题here昨天,这家伙尝试用一种颜色为 TextBlock 中的文本着色,用另一种颜色为下划线着色,这显然是不可能的。
我尝试耍聪明,想要应用一个LinearGradiantBrush
,这样我就可以用另一个颜色和文本强制下划线:
<TextBlock Margin="68,232,124,300" FontSize="35">
<Underline>
<Underline.Foreground>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Red" Offset="0.764"/>
<GradientStop Color="White" Offset="0.773"/>
</LinearGradientBrush>
</Underline.Foreground>
Here s my text
</Underline>
</TextBlock>
正如您所看到的,GradiantBrush 是单独应用的,很奇怪,但为什么?
我期望它从额外的底部到额外的顶部从白色渐变到红色(包括全部作为一个对象的线),而不是像这里显示的那样。
这正常吗?应该是这样吗?
更新:
这种行为在 WPF 中也存在。
最佳答案
Windows Phone 中的 TextDecorations 几乎没有限制 - Windows Phone 继承了 Silverlight 功能,因此 only Underline is available.
除此之外,似乎 TextBlock.Foreground
和 Underline.Foreground
彼此绑定(bind)(或者是相同的属性?)。 TextDecoration 是一个附加元素,因此 Brush 是单独应用的(如果我错了,请纠正我)。
由于这些限制,我们无法做到 like this .
关于c# - LinearGradiantBrush 单独应用于下划线和文本,但不一起应用于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21676101/