WPF中的.NET Framework 4不显示位图效果 [英] .NET Framework 4 in WPF not showing bitmap effect

查看:101
本文介绍了WPF中的.NET Framework 4不显示位图效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用带有位图效果的VS2010和框架版本4时遇到问题。如果我有下面的代码,并使用.NET Framework 4 Client Profile在WPF应用程序中运行它,则不会出现位图效果。如果我将框架版本设置为.NET Framework 3.5 Client Profile(并且不更改任何代码),它将按预期运行。刚开始,我认为这是我的应用程序中的一个问题,但是我删除了代码并将其放在单独的独立应用程序中,并且其行为相同。其他人可以验证是否发生了相同的问题吗?

I am having a problem using VS2010 and framework version 4 with bitmap effects. If I have the code below and run it in a WPF application using the .NET Framework 4 Client Profile, the bitmap effect does not appear. If I set the framework version to .NET Framework 3.5 Client Profile (and change no code), it runs as expected. At first, I thought it was a problem in my application, but I removed the code and put it in a separate standalone application and it behaves the same. Anyone else verify that the same problem happens?

这里发生了什么?

VS2010中的第4版框架只是似乎忽略了位图效果。

The version 4 framework in VS2010 just seems to ignore the bitmap effect.

<Window.Resources>
    <Style x:Key="SectionHeaderTextBlockStyle" TargetType="{x:Type TextBlock}">
        <Setter Property="FontFamily" Value="Segoe UI"/>
        <Setter Property="FontSize" Value="18"/>
        <Setter Property="FontWeight" Value="Bold"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="Foreground" Value="LightGreen"/>
        <Setter Property="BitmapEffect">
            <Setter.Value>
                <OuterGlowBitmapEffect GlowColor="Black"  GlowSize="3" />
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>

<Grid VerticalAlignment="Center" HorizontalAlignment="Center">
    <TextBlock Text="Contact Details" Style="{DynamicResource SectionHeaderTextBlockStyle}"/>
</Grid>


推荐答案

正如其他人所述:.NET 4.0不再支持BitmapEffects。

As stated by others already: .NET 4.0 no longer supports BitmapEffects.

作为附加信息:由于没有 OuterGlowEffect ,您可以将其与<$ c一起使用$ c>效果属性(至少我不知道),您可以使用 DropShadowEffect 并设置其 ShadowDepth 属性设置为0。然后,您可以通过调整 BlurRadius 属性。此外,您还可以调整 Color 属性,如果您希望辉光具有不同于黑色的其他颜色,但是正如我从代码示例中看到的那样,您实际上使用黑色作为 GlowColor

As an additional info: Since there is no OuterGlowEffect which you can use with the Effect property (at least none that I am aware of), you can replace the bitmap effect with a DropShadowEffect and set its ShadowDepth property to 0. Then you can create a glow effect by adjusting the BlurRadius property. Furthermore, you can also adjust the Color property if you want the glow to have another color than black, but as I see from your code sample, you actually use black as the GlowColor.

我知道这种解决方法可能不如 OuterGlowBitmapEffect 并不会产生相同的结果,但是至少在某些情况下它会接近,并且绝对比自己编写像素着色器更容易...

I know this workaround might not be as flexible and comfortable as the OuterGlowBitmapEffect and it does not produce identical results, but at least it comes close in some situations, and it is definitely easier than writing a pixel shader yourself...

这篇关于WPF中的.NET Framework 4不显示位图效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆