今天学习了Silverlight中Effect.下面是我总结的。直接贴代码了
(1)前台代码
(2)后台代码
View Code
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; //添加命名空间 using System.Windows.Media.Effects; namespace SLEffectDemo { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); this.btnBlurEffect.Click += new RoutedEventHandler(btnBlurEffect_Click); this.btnBlurEffectAnimation.Click += new RoutedEventHandler(btnBlurEffectAnimation_Click); this.btnnDropShadowEffect.Click += new RoutedEventHandler(btnnDropShadowEffect_Click); this.btnnDropShadowEffectAnimation.Click += new RoutedEventHandler(btnnDropShadowEffectAnimation_Click); } void btnBlurEffect_Click(object sender, RoutedEventArgs e) { Button btn = sender as Button; if (btn.Effect != null) { btn.Effect = null; } else { BlurEffect blurEffect = new BlurEffect(); blurEffect.Radius = 5; btn.Effect = blurEffect; } } void btnBlurEffectAnimation_Click(object sender, RoutedEventArgs e) { this.myBlurEffectStoryboard.Begin(); } void btnnDropShadowEffect_Click(object sender, RoutedEventArgs e) { Button btn = sender as Button; if (btn.Effect != null) { btn.Effect = null; } else { Color color=new Color(); color.A=255; color.B=50; color.R=50; color.G=50; DropShadowEffect dropShadowEffect = new DropShadowEffect(); dropShadowEffect.Color = color; dropShadowEffect.Direction = 800; dropShadowEffect.ShadowDepth = 25; dropShadowEffect.BlurRadius = 6; dropShadowEffect.Opacity = 0.5; btn.Effect = dropShadowEffect; } } void btnnDropShadowEffectAnimation_Click(object sender, RoutedEventArgs e) { myDropShadowEffectStoryboard.Begin(); } } }