通常在做SilverLight 过程中,我们不得不实现一些特效,来达到用户的需求,下面是实现按钮的阴影特效,只要鼠标移到button上就启动特效。鼠标离开时我们清除特效:

  1. <Grid x:Name&#61;"LayoutRoot" Background&#61;"White"> 
  2.     <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" /> 
  3. Grid> 

 

 

只加了一个 button控件。其他什么都没有

 

然后是后台代码&#xff1a;

 

  1. 1:  namespace SilverlightApplication20  
  2. 2:  {  
  3. 3:      public partial class MainPage : UserControl  
  4. 4:      {  
  5. 5:          public MainPage()  
  6. 6:          {  
  7. 7:              InitializeComponent();  
  8. 8:              button1.MouseEnter &#43;&#61; new MouseEventHandler(button1_MouseEnter);  
  9. 9:              button1.MouseLeave &#43;&#61; new MouseEventHandler(button1_MouseLeave);  
  10. 10:          }  
  11. 11:    
  12. 12:          void button1_MouseLeave(object sender, MouseEventArgs e)  
  13. 13:          {  
  14. 14:              button1.Effect &#61; null;  
  15. 15:          }  
  16. 16:    
  17. 17:          void button1_MouseEnter(object sender, MouseEventArgs e)  
  18. 18:          {  
  19. 19:              System.Windows.Media.Effects.DropShadowEffect ds &#61; new System.Windows.Media.Effects.DropShadowEffect();  
  20. 20:              ds.ShadowDepth &#61; 0;  
  21. 21:              ds.Color &#61; Colors.Yellow;  
  22. 22:              button1.Effect &#61; ds;  
  23. 23:          }  
  24. 24:      }  
  25. 25:  }  
  26. 26: 

 

好了 ,现在就去看看效果吧&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;