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

 
  
  1. <Grid x:Name="LayoutRoot" Background="White"> 
  2.     <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="10,10,0,0" Name="button1" VerticalAlignment="Top" Width="75" /> 
  3. </Grid> 

 

 

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

 

然后是后台代码:

 

 
  
  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 += new MouseEventHandler(button1_MouseEnter);  
  9. 9:              button1.MouseLeave += new MouseEventHandler(button1_MouseLeave);  
  10. 10:          }  
  11. 11:    
  12. 12:          void button1_MouseLeave(object sender, MouseEventArgs e)  
  13. 13:          {  
  14. 14:              button1.Effect = null;  
  15. 15:          }  
  16. 16:    
  17. 17:          void button1_MouseEnter(object sender, MouseEventArgs e)  
  18. 18:          {  
  19. 19:              System.Windows.Media.Effects.DropShadowEffect ds = new System.Windows.Media.Effects.DropShadowEffect();  
  20. 20:              ds.ShadowDepth = 0;  
  21. 21:              ds.Color = Colors.Yellow;  
  22. 22:              button1.Effect = ds;  
  23. 23:          }  
  24. 24:      }  
  25. 25:  }  
  26. 26: 

 

好了 ,现在就去看看效果吧!!!!!!!!