Wednesday, July 28, 2010

Visual Effects in WPF ( Blur, DropShadow, OuterGlow )

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

8 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hello and thank you for the tut!
    Is it possible to apply the drop shadow effect on the inner text of a button instead to its border on mouseover?
    Thank you!

    ReplyDelete
    Replies
    1. Hi, you have to create it this way

      http://stackoverflow.com/questions/17515631/add-an-image-in-a-wpf-button

      Saludos desde Chile

      Delete
  3. An impressive share, I just given this onto a colleague who was doing slightly evaluation on this. And he the truth is purchased me breakfast because I found it for him.. smile. So let me reword that: Thnx for the treat! However yeah Thnkx for spending the time to discuss this, I feel strongly about it and love reading more on this topic. If attainable, as you develop into expertise, would you mind updating your blog with extra details? It's extremely useful for me. Big thumb up for this weblog put up! gsn casino slots

    ReplyDelete
  4. Great little tutorial. It's simple but very useful. Should have been included in the MSDN.

    ReplyDelete
  5. How edit blur radius in code(C#)?

    ReplyDelete
  6. merkur 10 merkur futur gold slot machine blackjack review
    We will give you access to the review of merkur gold slot machine. Merkur Progress Adjustable 메리트 카지노 쿠폰 Slots. 1/3.6/10/10. Merkur Progress Adjustable Slots. 1/3.6/10. Merkur Progress Adjustable Slots.

    ReplyDelete
  7. Harrah's Hotel and Casino - Mapyro
    Hotel and Casino. 3450 Las Vegas Blvd South, Las 광양 출장마사지 Vegas, NV 89109, United States. Phone: (702) 경상북도 출장안마 770-7000. Website: 김포 출장샵 www.harrahs.com. Check reviews, Photos & Rates  Rating: 3.8 구리 출장마사지 · ‎1,726 강릉 출장샵 votes

    ReplyDelete