通常在做SilverLight 过程中,我们不得不实现一些特效,来达到用户的需求,下面是实现按钮的阴影特效,只要鼠标移到button上就启动特效。鼠标离开时我们清除特效:
- <Grid x:Name&#61;"LayoutRoot" Background&#61;"White">
- <Button Content&#61;"Button" Height&#61;"23" HorizontalAlignment&#61;"Left" Margin&#61;"10,10,0,0" Name&#61;"button1" VerticalAlignment&#61;"Top" Width&#61;"75" />
- Grid>
只加了一个 button控件。其他什么都没有
然后是后台代码&#xff1a;
- 1: namespace SilverlightApplication20
- 2: {
- 3: public partial class MainPage : UserControl
- 4: {
- 5: public MainPage()
- 6: {
- 7: InitializeComponent();
- 8: button1.MouseEnter &#43;&#61; new MouseEventHandler(button1_MouseEnter);
- 9: button1.MouseLeave &#43;&#61; new MouseEventHandler(button1_MouseLeave);
- 10: }
- 11:
- 12: void button1_MouseLeave(object sender, MouseEventArgs e)
- 13: {
- 14: button1.Effect &#61; null;
- 15: }
- 16:
- 17: void button1_MouseEnter(object sender, MouseEventArgs e)
- 18: {
- 19: System.Windows.Media.Effects.DropShadowEffect ds &#61; new System.Windows.Media.Effects.DropShadowEffect();
- 20: ds.ShadowDepth &#61; 0;
- 21: ds.Color &#61; Colors.Yellow;
- 22: button1.Effect &#61; ds;
- 23: }
- 24: }
- 25: }
- 26:
好了 ,现在就去看看效果吧&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;