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