Provides Lightweight alternatives for dropshadowbitmapeffect in WPF

Source: Internet
Author: User
Provides Lightweight alternatives for dropshadowbitmapeffect in WPF
Zhou yinhui

WPF has an exciting new feature: We can easily provide bitmapeffect for visual elements, such as shadows. however, it is frustrating that bitmap results consume a lot of CPU resources. From the usual development, we can come up with two experiences: 1. Use bitmap effects as little as possible, because it is calculated by the CPU rather than the GPU. 2. Do not use bitmap effects with animations that are a little more complex. It often makes the animation not smooth.
In the bitmap effect, dropshadowbitmapeffect is the most common one. Here, systemdropshadowbitmapeffect, a substitute for dropshadowchrome, is not perfect, however, it is often a good solution to dropshadowbitmapeffect performance problems.
We can use a systemdropshadowchrome object that will act as the "shadow" and then use the object to add the shadow as the child of the systemdropshadowchrome object, which is the same as a border object.

In, the shadow effect of the pale blue square is obtained using our systemdropshadowchrome. The shadow effect of the Orange square is obtained using dropshadowbitmapeffect. You can paste the following Code View on xamlpad: < Page Xmlns = "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x = "Http://schemas.microsoft.com/winfx/2006/xaml"
Xmlns: = "CLR-namespace: Microsoft. Windows. themes; Assembly = presentationframework. Aero"   >
< Grid Width = "579" Height = "492" >

< A: systemdropshadowchrome Width = "75" Cornerradius = "3,13, 3,13" Rendertransformorigin = "0.5, 0.5" Horizontalalignment = "Left" Margin = "185,149" X: Name = "Systemdropshadowchrome" Verticalalignment = "TOP" Height = "75" >
< Border Background = "Lightblue" Cornerradius = "3,13, 3,13" Margin = "1, 1, 1"   />
</ A: systemdropshadowchrome >

< Border Background = "# Ffe78e16" Cornerradius = "3,13, 3,13" Rendertransformorigin = "0.5, 0.5" Horizontalalignment = "Left" Margin = "0,132" X: Name = "Border" Verticalalignment = "Bottom" Width = "75" Height = "75"   >
< Border . Bitmapeffect >
< Dropshadowbitmapeffect Shadowdepth = "2" />
</ Border. bitmapeffect >
</ Border >
</ Grid >
</ Page >

In addition, the color of the shadow can be set. You only need to set the color attribute of the systemdropshadowchrome object.
Unfortunately, the systemdropshadowchrome object cannot set shadows for elements in other shapes, because its own shape can only be square or rounded.

You can click here or here to view more discussions about systemdropshadowchrome.

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.