WPF 中的 OuterGlow 效果不适用于分层窗口?

发布于 2024-10-13 07:17:57 字数 1080 浏览 4 评论 0原文

谁能告诉我为什么 /no/outerglow 效果在我的 WPF 窗口上起作用?这是代码示例:

<Window x:Class="SocialShock_WPF_Client.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        AllowsTransparency="True" 
        WindowStyle='None' 
        Background="Transparent" 
        Loaded="Window_Loaded">
    <Grid>
        <Rectangle Margin="12" Name="rectangle1" Fill="#FFB75050">
            <Rectangle.BitmapEffect>
                <OuterGlowBitmapEffect GlowColor="Black" GlowSize="20" />
            </Rectangle.BitmapEffect>
        </Rectangle>
    </Grid>
</Window>

以及生成的图像:

http://img408.imageshack .us/img408/6213/1c1761f31ce6408d948e266.png

边缘没有发光。 不仅矩形上没有出现发光,而且我添加到窗口的任何其他控件也无法接受发光。

编辑:它在.Net 4.0中

can any one tell me why /no/ outerglow effects are working on my WPF Window? here is an example of the code:

<Window x:Class="SocialShock_WPF_Client.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        AllowsTransparency="True" 
        WindowStyle='None' 
        Background="Transparent" 
        Loaded="Window_Loaded">
    <Grid>
        <Rectangle Margin="12" Name="rectangle1" Fill="#FFB75050">
            <Rectangle.BitmapEffect>
                <OuterGlowBitmapEffect GlowColor="Black" GlowSize="20" />
            </Rectangle.BitmapEffect>
        </Rectangle>
    </Grid>
</Window>

and the resulting image:

http://img408.imageshack.us/img408/6213/1c1761f31ce6408d948e266.png

No glow around the edge.
not only is the glow not appearing on the rectangle, but any other controls i add to the window cannot accept glows either.

EDIT: its in .Net 4.0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染墨丶若流云 2024-10-20 07:17:57

.NET 4.0 不再支持 BitmapEffects。

来自 MSDN

重要信息在 .NET Framework 4 或
之后,BitmapEffect类是
过时的。如果您尝试使用
BitmapEffect 类,你会得到一个
过时的异常。未过时的
BitmapEffect 类的替代方案
是效果类。在大多数
情况下,Effect 类是
明显更快。

没有真正好的替代品,但您可以尝试使用 DropShadowEffectShadowDepth 为 0。示例

<Rectangle Margin="12" Name="rectangle1" Fill="#FFB75050">
    <Rectangle.Effect>
        <DropShadowEffect ShadowDepth="0"
                          Color="Black"
                          Opacity="1"
                          BlurRadius="12"/>
    </Rectangle.Effect>
</Rectangle>

如果我理解您的评论正确,

添加效果在代码后面

DropShadowEffect dropShadowEffect = new DropShadowEffect();
dropShadowEffect.ShadowDepth = 0;
dropShadowEffect.Color = Colors.Black;
dropShadowEffect.Opacity = 1;
dropShadowEffect.BlurRadius = 12;
rectangle1.Effect = dropShadowEffect;

修改代码后面的效果

DropShadowEffect dropShadowEffect = rectangle1.Effect as DropShadowEffect;
dropShadowEffect.BlurRadius = 24;

BitmapEffects are no longer supported in .NET 4.0.

From MSDN

Important In the .NET Framework 4 or
later, the BitmapEffect class is
obsolete. If you try to use the
BitmapEffect class, you will get an
obsolete exception. The non-obsolete
alternative to the BitmapEffect class
is the Effect class. In most
situations, the Effect class is
significantly faster.

There isn't a really good substitute but you can try to use a DropShadowEffect with a ShadowDepth of 0. Example

<Rectangle Margin="12" Name="rectangle1" Fill="#FFB75050">
    <Rectangle.Effect>
        <DropShadowEffect ShadowDepth="0"
                          Color="Black"
                          Opacity="1"
                          BlurRadius="12"/>
    </Rectangle.Effect>
</Rectangle>

If I understood you comment correctly,

Adding the effect in code behind

DropShadowEffect dropShadowEffect = new DropShadowEffect();
dropShadowEffect.ShadowDepth = 0;
dropShadowEffect.Color = Colors.Black;
dropShadowEffect.Opacity = 1;
dropShadowEffect.BlurRadius = 12;
rectangle1.Effect = dropShadowEffect;

Modifying the effect in code behind

DropShadowEffect dropShadowEffect = rectangle1.Effect as DropShadowEffect;
dropShadowEffect.BlurRadius = 24;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文