【问题标题】:WPF DropShadow Effect disapear when setting background color of control设置控件背景颜色时WPF DropShadowEffect消失
【发布时间】:2013-05-13 13:31:08
【问题描述】:

在这个例子中,我有一个TextBlock 和一个DropShadowEffect:

<TextBlock Foreground="Black" Text="All Tasks">
    <TextBlock.Effect>
        <DropShadowEffect ShadowDepth="1.2" 
                          Direction="270" 
                          Opacity="0.6" 
                          BlurRadius="1" 
                          Color="Red"/>
    </TextBlock.Effect>
</TextBlock>

这会产生以下输出:

如果我为TextBlock 设置任何背景颜色,阴影应该会消失:

如何在保持投影的同时设置此属性?

【问题讨论】:

  • 我相信这是因为您使用的是纯色背景。

标签: wpf styles dropshadow


【解决方案1】:

DropShadowEffect 不会消失 - 它现在适用于整个矩形。

这会产生预期的效果:

<Border Background="Green">
    <TextBlock Foreground="Black" Text="All Tasks">
        <TextBlock.Effect>
            <DropShadowEffect ShadowDepth="1.2" 
                              Direction="270" 
                              Opacity="0.6" 
                              BlurRadius="1" 
                              Color="Red"/>
        </TextBlock.Effect>
    </TextBlock>
</Border>

【讨论】:

  • 感谢您的回答。你能解释一下为什么 WPF 会有这种行为吗?
猜你喜欢
  • 2015-09-05
  • 1970-01-01
  • 1970-01-01
  • 2011-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多