【问题标题】:LinearGradiantBrush applied on the underline and the text separately but not togetherLinearGradiantBrush 分别应用于下划线和文本,但不一起
【发布时间】:2014-02-10 11:35:58
【问题描述】:

我昨天试图回答一个问题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 中。

【问题讨论】:

  • FWIW,代码截图让其他人更难测试代码,因为他们需要全部输入,而不是粘贴到测试应用程序中。此外,该问题在搜索引擎中的曝光率也较低。
  • @WaltRitscher:我更新了我的问题

标签: c# wpf silverlight xaml windows-phone-8


【解决方案1】:

Windows Phone 中的 TextDecorations 几乎没有限制 - Windows Phone 继承了 Silverlight 功能,因此 only Underline is available.

除此之外,TextBlock.ForegroundUnderline.Foreground 似乎相互绑定(或者是相同的属性?)。 TextDecoration 是一个附加元素,因此 Brush 是单独应用的(如果我错了,请纠正我)。

由于这些限制,我们无法做到like this

【讨论】:

  • 我不确定,但你怎么能确定 TextDecoration 是一个附加元素? TextBlock 样式甚至是空的,我猜它是一个整体的统一元素,还是我错了?
  • @AymenDaoudi 我找不到有关此的文档。我怀疑 Underline 是 TextDecorations Collection 中的一个对象。
  • 正如你所见,我没有使用 TextDecoration,我使用的是内联的 Underline,内联本身具有 TextDecorations 作为属性,所以我推断它们不一样,你看我的意思是什么?
  • @AymenDaoudi 我认为它们是相同的(认为这是我的下一个怀疑)。可能 Underline 构造函数将 TextDecoration.Underline 添加到 TextDecorations Collections。对我来说也不清楚。我明白你的观点并同意这有点奇怪。对于许多人的怀疑 - 我将删除我的答案,看看其他人怎么说。
  • 没关系别删了,我们拭目以待
【解决方案2】:

WPF中下划线的颜色可以改变。

WPF XAML

<TextBlock FontSize="35" Foreground='Red'
           Text='Here is my text'>
  <TextBlock.TextDecorations>
    <TextDecoration>
      <TextDecoration.Pen>
        <Pen Brush='Orange' />
      </TextDecoration.Pen>
    </TextDecoration>
  </TextBlock.TextDecorations>

</TextBlock>

这在 Windows Phone 和 Silverlight 实现中似乎是不可能的。

一种可能是使用带有内置下划线的字体。

Example of Underline typeface

在这种情况下,渐变可能会起作用,因为下划线是单词的一部分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-15
    • 2013-08-22
    • 1970-01-01
    • 2020-08-21
    • 2022-07-17
    相关资源
    最近更新 更多