silverlight 鼠标事件处理

2015-12-31 07:58:53来源:cnblogs.com作者:颍川小哥人点击

托管代码注册鼠标事件

不需要再.xaml中声明注册事件。

.xaml

 <Ellipse Name="ellipse" Width="120" Height="120" Fill="Orange"                      Canvas.Top="60" Canvas.Left="80"/>

区别于在.xaml中注册事件

 <Ellipse Name="ellipse" Width="120" Height="120" Fill="Orange"                      Canvas.Top="60" Canvas.Left="80" MouseEnter="OnMouseEnter"/>

 

然后再.c# 中进行鼠标事件的注册,放在MainPage 中

public MainPage()        {            InitializeComponent();                      ellipse.MouseEnter += new MouseEnterHander(OnMouseEnter);            ellipse.MouseLeave += new MouseEnterHander(OnMouseEnter);
}

void OnMouseEnter(object sender, MouseEventArgs e)
{
Ellipse m = sender as Ellipse;
m.Fill=new SolidColorBrush(Color.Green);
}

在获取时间的时候可以在

 ellipse.MouseEnter +=   直接连击Tab  
 public MainPage()        {            InitializeComponent();                       ellipse.MouseEnter += Ellipse_MouseEnter;            ellipse.MouseLeave += Ellipse_MouseLeave;                    }    private void Ellipse_MouseLeave(object sender,MouseEventArgs e)        {            Ellipse ell = sender as Ellipse;            ell.Fill = new SolidColorBrush(Colors.Gray);        }    private void Ellipse_MouseEnter(object sender, MouseEventArgs e)        {            Ellipse ell = sender as Ellipse;            ell.Fill = new SolidColorBrush(Colors.Black);        }

 

 

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台