Visual Effects in WPF ( Blur, DropShadow, OuterGlow )

refs:

http://wpftoturials.blogspot.com/2010/07/visual-effects-in-wpf-blur-dropshadow.html


WPF provides visual effects that you can apply to any element. The goal of effects is to give you an easy, to enhance the appearance of buttons, text,container controls and other WPF controls. With the power of WPF you can make all effects in xaml too but rather than your own drawing code, you simply use one of the classes that derives from Effect (in the System.Windows.Media.Effects namespace).

Following are the list of classes that you can use
Name
Description
BlurEffect
ShaderEffect
DropShadowEffect
Blurs the content in your element
Applies pixel shader
Adds a rectangular drop shadow behing your control
Now we will discuss all these effects one by one.

Blureffect
Most easy to use effect in wpf is Blureffect, its blurs any content of control, it though as you are looking at it through an out of focus lens. You can inrease this effect by inreasing by its radius property. Lets write some code that will blur the content of button.

<Button Height="40" Width="100" Content="Blur effect with radius 2">
<Button.Effect>
<BlurEffect Radius="2"></BlurEffect>
</Button.Effect>
</Button>
<Button Height="40" Width="100" Content="Blur effect with radius 5">
<Button.Effect>
<BlurEffect Radius="3.5"></BlurEffect>
</Button.Effect>
</Button>
<Button Height="40" Width="100" Content="Blur effect with radius 5">
<Button.Effect>
<BlurEffect Radius="5"></BlurEffect>
</Button.Effect>
</Button>

DropShadowEffect
Its really very good and powerfull class of wpf, by using this class you can make outer glow of content also.
lets write some code for drop shadow first
<Button Height="40" Width="100" Content="Blur effect with radius 2">
<Button.Effect>
<BlurEffect Radius="2"></BlurEffect>
</Button.Effect>
</Button>
<Button Height="40" Width="100" Content="Blur effect with radius 5">
<Button.Effect>
<BlurEffect Radius="3.5"></BlurEffect>
</Button.Effect>
</Button>
<Button Height="40" Width="100" Content="Blur effect with radius 5">
<Button.Effect>
<BlurEffect Radius="5"></BlurEffect>
</Button.Effect>
</Button>

OuterGlow
<Button Content="Out glow by setting BlurRadius=50 and shadowdepth=0">
<Button.Effect>
<DropShadowEffect BlurRadius="50" ShadowDepth="0"/>
</Button.Effect>
</Button>
<Button Content="Out glow by setting BlurRadius=50 and shadowdepth=0">
<Button.Effect>
<DropShadowEffect BlurRadius="20" ShadowDepth="0"/>
</Button.Effect>
</Button>
<Button Content="Drop shadow effect with BlurRadius=10 and ShadowDepth=5">
<Button.Effect>
<DropShadowEffect BlurRadius="10" ShadowDepth="5"/>
</Button.Effect>
</Button>
<Button Content="Drop shadow effect by setting BlurRadius=10 and ShadowDepth=20">
<Button.Effect>
<DropShadowEffect BlurRadius="10" ShadowDepth="20"/>
</Button.Effect>
</Button>


ShaderEffect

The ShaderEffect class doesn’t represent a ready-to-use effect. Instead, it’s an abstract class from which
you derive to create your own custom pixel shaders. By using ShaderEffect (or a custom effect that
derives from it), you gain the ability to go far beyond more blurs and drop shadows

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值