如何将效果应用于WPF中的边框而不应用于其内容?
我有一个WPF应用程序,它有一个第三方数据网格,周围有一个边框。我使用了如何将效果应用于WPF中的边框而不应用于其内容?,wpf,border,Wpf,Border,我有一个WPF应用程序,它有一个第三方数据网格,周围有一个边框。我使用了DropShadowEffect在边框后面放置阴影,但这似乎会在一定程度上影响性能(不如BitmapEffect,但仍然很明显),并使字体呈现模糊。是否有一种方法可以将效果应用于边界,而不是其内容 我尝试将内容的效果设置为{x:Null},但没有帮助 下面是我开发的一个示例应用程序。它在边框后面放置阴影,但在每行文本后面也放置阴影。我想要边框后面的阴影,但不想要文本 <Window x:Class="WpfEffect
DropShadowEffect
在边框后面放置阴影,但这似乎会在一定程度上影响性能(不如BitmapEffect
,但仍然很明显),并使字体呈现模糊。是否有一种方法可以将效果应用于边界,而不是其内容
我尝试将内容的效果设置为{x:Null}
,但没有帮助
下面是我开发的一个示例应用程序。它在边框后面放置阴影,但在每行文本后面也放置阴影。我想要边框后面的阴影,但不想要文本
<Window x:Class="WpfEffectTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Border BorderBrush="Black" BorderThickness="10" CornerRadius="5" Margin="25">
<Border.Effect>
<DropShadowEffect BlurRadius="10" ShadowDepth="5" />
</Border.Effect>
<StackPanel>
<TextBlock>This is some text</TextBlock>
<TextBlock>This is some text</TextBlock>
<TextBlock>This is some text</TextBlock>
<TextBlock>This is some text</TextBlock>
<TextBlock>This is some text</TextBlock>
<TextBlock>This is some text</TextBlock>
</StackPanel>
</Border>
</Grid>
</Window>
这是一些文本
这是一些文本
这是一些文本
这是一些文本
这是一些文本
这是一些文本
一个简单的(黑客?)解决方案是
<StackPanel Background="White">
这应该可以解决文本的阴影问题(但不确定性能问题)。
问题是WPF将效果应用于视觉树中的set元素及其所有子元素。
此链接更好地解释了这一点:
来自gcores的链接给出了答案,即将边框及其内容放在同一个网格中,以便内容覆盖边框
<Window x:Class="WpfEffectTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Border BorderBrush="Black" BorderThickness="10" CornerRadius="5" Margin="25">
<Border.Effect>
<DropShadowEffect BlurRadius="10" ShadowDepth="5" />
</Border.Effect>
</Border>
<StackPanel Margin="35">
<TextBlock>This is some text</TextBlock>
<TextBlock>This is some text</TextBlock>
<TextBlock>This is some text</TextBlock>
<TextBlock>This is some text</TextBlock>
<TextBlock>This is some text</TextBlock>
<TextBlock>This is some text</TextBlock>
</StackPanel>
</Grid>
</Window>
这是一些文本
这是一些文本
这是一些文本
这是一些文本
这是一些文本
这是一些文本
为所有文本块尝试以下块(或类似块):
<TextBlock>
<TextBlock.Effect>
<DropShadowEffect BlurRadius="30" ShadowDepth="5" Color="White"/>
</TextBlock.Effect>
</TextBlock>