Silverlight & Blend Animation Design Series Seven: Blur Effect (blureffect) and Shadow effect (Dropshadoweffect)

Source: Internet
Author: User
Tags silverlight

The Blur effect (blureffect) and Shadow effect (Dropshadoweffect) are two very useful and commonly used two effects, such as in the development album, you can add a blur effect to the thumbnail image of the photo, Dynamically change the size of the photo and blur the transparency to achieve a magnified transparency as you zoom in on the photo.

First, fuzzy effect (blureffect)

Each object in Silverlight supports the addition of blur and shadow effects, and in the Blend tool, the Appearance panel allows you to visualize the blur and shadow effects, as well as adjust the effect parameters, directly and visually. such as the design of the Blur effect interface:

        

Clicking "New" will pop up the blur and shadow effects selection dialog box for the Blur and shadow effects selection dialog box:

        

Take the photo album development of a typical example to analyze it, such as the photo by default reduced to a certain proportion and added a blur effect rendered in the photo list, when the mouse points to the photo to enlarge the picture (enlarge the image can be achieved by zooming animation, detailed: "Silverlight & Blend Animation Design Series three: Zoom animation (ScaleTransform)), and dynamically change its blur effect value of 0 to achieve a clear view of the photo effect. The following XAML defines a picture:

<image height= "x:name=" Flower "width=" "source=" Yellowflower.jpg "opacity=" 1 "
canvas.left= "canvas.top=" rendertransformorigin= "0.5,0.5"
Mouseenter= "Flower_mouseenter" mouseleave= "Flower_mouseleave" opacitymask= "{x:null}" >
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
<Image.Effect>
<BlurEffect/> <!--adds a blur effect to the picture--
</Image.Effect>
</Image>

It can be handled by two animations, one completes zooming in on the image (scalex,scaley:1-->2) while changing its blur value to 0 (radius:5-->0), and the other animation is the opposite.

<storyboard x:name= "Flower_enter" >
<doubleanimation begintime= "00:00:00" storyboard.targetname= "Flower" duration= "00:00:00.50" To= "2"
Storyboard.targetproperty= "(uielement.rendertransform). (TransformGroup.Children) [0]. (Scaletransform.scalex) ">
</DoubleAnimation>
<doubleanimation begintime= "00:00:00" storyboard.targetname= "Flower" duration= "00:00:00.50" To= "2"
Storyboard.targetproperty= "(uielement.rendertransform). (TransformGroup.Children) [0]. (Scaletransform.scaley) ">
</DoubleAnimation>
<doubleanimation begintime= "00:00:00" storyboard.targetname= "Flower" duration= "00:00:00.50" To= "0"
Storyboard.targetproperty= "(uielement.effect). (Blureffect.radius) ">
</DoubleAnimation>
</Storyboard>
<storyboard x:name= "Flower_level" >
<doubleanimation begintime= "00:00:00" storyboard.targetname= "Flower" duration= "00:00:00.50" To= "1"
Storyboard.targetproperty= "(uielement.rendertransform). (TransformGroup.Children) [0]. (Scaletransform.scalex) ">
</DoubleAnimation>
<doubleanimation begintime= "00:00:00" storyboard.targetname= "Flower" duration= "00:00:00.50" To= "1"
Storyboard.targetproperty= "(uielement.rendertransform). (TransformGroup.Children) [0]. (Scaletransform.scaley) ">
</DoubleAnimation>
<doubleanimation begintime= "00:00:00" storyboard.targetname= "Flower" duration= "00:00:00.5000000" To= "5"
Storyboard.targetproperty= "(uielement.effect). (Blureffect.radius) ">
</DoubleAnimation>
</Storyboard>

The execution of the two animations defined above is triggered dynamically by mouse events (Mouseenter,mouseleave) to achieve the desired purpose, as follows:

private void Flower_mouseenter (object sender, System.Windows.Input.MouseEventArgs e)
{
Todo:add event handler implementation here.
This. Flower_enter.begin ();
}

private void Flower_mouseleave (object sender, System.Windows.Input.MouseEventArgs e)
{
Todo:add event handler implementation here.
This. Flower_level.begin ();
}

      

Second, shadow effect (Dropshadoweffect)

Applying shadow effects in Silverlight is as simple as blurring effects, and adding shadow effects to an element in the same way you add a blur effect, you need to focus on setting the relevant properties of the shadow effect.

Blurradius: Blur Radius
Color: Fill Color
Direction: Direction
Opacity: Transparency
Shadowdepth: Shadow Depth

The design of the shadow effect can be accomplished by setting the properties options above, as the design process is very simple, as shown in detail:

The corresponding generated XAML code is as follows:

<image height= "x:name=" Flower "width=" "canvas.left=" canvas.top= "180"
Source= "Yellowflower.jpg" stretch= "Fill" cursor= "Hand" >
<Image.Effect>
<dropshadoweffect x:name= "Flowershadow"
blurradius= "18"
Shadowdepth= "27"
opacity= "0.6"
direction= "321"/>
</Image.Effect>
</Image>

Silverlight & Blend Animation Design Series Seven: Blur Effect (blureffect) and Shadow effect (Dropshadoweffect)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.