如何:创建多个可视化效果

更新:2007 年 11 月

使用 BitmapEffectGroup 可将多种可视效果应用于一个可视对象。下面的示例演示如何应用 BlurBitmapEffectDropShadowBitmapEffect 以创建背后具有阴影的模糊按钮。

示例

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Effects;

namespace SDKSample
{
    public partial class MultipleEffectExample : Page
    {
        public MultipleEffectExample()
        {
            Button myButton = new Button();
            myButton.Content = "DropShadow under this Button";
            myButton.Margin = new Thickness(50);
            myButton.Width = 300;

            // Create the BitmapEffects to apply to the button.
            BlurBitmapEffect myBlurBitmapEffect = new BlurBitmapEffect();
            myBlurBitmapEffect.Radius = 2;

            DropShadowBitmapEffect myDropShadowBitmapEffect = new DropShadowBitmapEffect();
            myDropShadowBitmapEffect.Color = Colors.Black;
            myDropShadowBitmapEffect.Direction = 320;
            myDropShadowBitmapEffect.ShadowDepth = 30;
            myDropShadowBitmapEffect.Softness = 1;
            myDropShadowBitmapEffect.Opacity = 0.5;

            BitmapEffectGroup myBitmapEffectGroup = new BitmapEffectGroup();
            myBitmapEffectGroup.Children.Add(myBlurBitmapEffect);
            myBitmapEffectGroup.Children.Add(myDropShadowBitmapEffect);

            myButton.BitmapEffect = myBitmapEffectGroup;

            StackPanel myStackPanel = new StackPanel();
            myStackPanel.Children.Add(myButton);
            this.Content = myStackPanel;

        }      
    }
}
<Page xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml">

  <StackPanel>

    <Button Margin="50" Width="300">
      DropShadow Under this Button
      <Button.BitmapEffect>
        <BitmapEffectGroup>
          <BlurBitmapEffect Radius="2" />
          <DropShadowBitmapEffect Color="Black" Direction="320" ShadowDepth="30" Softness="1" 
           Opacity="0.5"/>
        </BitmapEffectGroup>
      </Button.BitmapEffect>
    </Button>

  </StackPanel>

</Page>

请参见

任务

如何:在对象的外边缘上创建发光效果

如何:向 Visual 应用模糊效果

如何:创建投影可视化效果

如何:对多个可视化效果进行动画处理

概念

位图效果概述