wpf 边框的外发光效果

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11124212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 23:27:02  来源:igfitidea点击:

Outer glow effect to border

wpfborderglowbitmapeffect

提问by Ponraja

How to provide the outer glow effect to border?

如何为边框提供外发光效果?

<Grid Width="200" Height="200">
    <Grid.Background>
        <RadialGradientBrush Center="0.5,0.5" GradientOrigin="0.5,0.5" RadiusX="0.8" RadiusY="0.8">
            <RadialGradientBrush.GradientStops>
                <GradientStop Offset="0" Color="#FF123B5F" />
                <GradientStop Offset="1" Color="#FF001F31" />
            </RadialGradientBrush.GradientStops>
        </RadialGradientBrush>
    </Grid.Background>
    <Border Width="180" Height="180" Margin="10" Background="Transparent"
            BorderBrush="White" BorderThickness="1">
        <Border.BitmapEffect>
            <OuterGlowBitmapEffect GlowColor="White" GlowSize="3" Opacity="1" />
        </Border.BitmapEffect>
    </Border>
</Grid>

I have tried this but it not working

我试过这个,但它不起作用

回答by Fredrik Hedblad

BitmapEffectsare no longer supported in .NET 4.0.

BitmapEffects.NET 4.0 不再支持。

From MSDN

来自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.

重要 在 .NET Framework 4 或更高版本中,BitmapEffect 类已过时。如果您尝试使用 BitmapEffect 类,您将得到一个过时的异常。BitmapEffect 类的非过时替代品是 Effect 类。在大多数情况下,Effect 类要快得多。

It isn't the same thing but you can try with a DropShadowEffectwith ShadowDepthclose to 0 instead.

这不是一回事,但您可以尝试DropShadowEffect使用ShadowDepth接近 0 的 a 代替。

Example

例子

<Border Width="180" Height="180" Margin="10" Background="Transparent"
        BorderBrush="White" BorderThickness="2" Opacity="1.0">
    <Border.Effect>
        <DropShadowEffect ShadowDepth="0"
                          Color="White"
                          Opacity="1"
                          BlurRadius="5"/>
    </Border.Effect>
</Border>

Comparison between the BitmapEffectsyou had and DropShadowEffectabove. DropShadowEffectto the right.

在比较BitmapEffects你必须和DropShadowEffect上面。DropShadowEffect向右。

enter image description here

在此处输入图片说明