首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >动态添加MouseLeftButtonUp事件

动态添加MouseLeftButtonUp事件
EN

Stack Overflow用户
提问于 2014-01-04 19:40:08
回答 1查看 433关注 0票数 0

我向MainWindow.xml添加了以下2种方法,但我无法触发该事件

代码语言:javascript
复制
private void Button_Click_2(object sender, RoutedEventArgs e)
{
    lstContacts.Items.Clear();
    cvMenuItem test = new cvMenuItem("test", Environment.GetEnvironmentVariable("USERPROFILE") + @"\Downloads\images.jpg");
    test.MouseLeftButtonUp += new System.EventHandler(imClicked);
    lstContacts.Items.Add(test);
}

void imClicked(object sender, EventArgs e)
{
    MessageBox.Show("hello");
}

我一直在犯这个错误,为什么?

无法隐式地将“System.EventHandler”类型转换为System.EventHandler MainWindow.xaml.cs 64 39 WpfApplication1

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-04 19:49:49

尝尝这个

代码语言:javascript
复制
test.MouseLeftButtonUp += imClicked;


private void imClicked(object sender, MouseButtonEventArgs e)
    {
             MessageBox.Show("hello");
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20925815

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档