动态创建按钮单击事件

编程入门 行业动态 更新时间:2024-10-17 19:26:26
本文介绍了动态创建按钮单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好,请帮帮我. 我有一个用户控件,我在放置在列表框项目模板中的home.xaml中使用了该控件.它像我的表一样动态创建时间. 我的问题是: 我需要动态创建按钮单击事件,在其中可以显示一个消息框,其中包含与特定按钮单击相关的数据 我提出了一个解决方案,例如:

Hello guys please help me in this. I have a usercontrol I am using that in my home.xaml which is placed in listbox item template. It dynamically creates number of time as in my table. My question is: I need to create dynamically button click event where I can display a messagebox which contain data related to that particular button click I came up a solution like:

public usercontrol() { InitializeComponent(); testButton.Click +=(s,e) => { if(buttonclick != null ) buttonclick(s,e); }; ...

您能否向我解释在单击事件的方式和位置,我们可以编写消息框? 谢谢!

Can you please explain to me how and where in the event click we can write messagebox? Thank you!

推荐答案

为什么不只是使用一种更易于维护的机制. Lamda表达式令人混淆,并不总是一个好主意. Why don''t you just use a more maintainable mechanism. Lamda expressions are obfuscatory and aren''t always a good idea. ... testButton.Click += new EventArgs(button_Click); ... <br /> private void buttonClick(object sender, EventArgs e) { // do whatever you need to have done }

为什么您不只是使用一种更易于维护的机制. Lamda表达式令人混淆,并不总是一个好主意. Why don''t you just use a more maintainable mechanism. Lamda expressions are obfuscatory and aren''t always a good idea. ... testButton.Click += new EventArgs(button_Click); ... <br /> private void buttonClick(object sender, EventArgs e) { // do whatever you need to have done }

嘿,我得到了答案,感谢所有想到这个问题的人,这就是答案 公共Usercontrol() { InitializeComponent(); ButtonExport.Click + =新的RoutedEventHandler(ButtonExport_Click); } void ButtonExport_Click(对象发送者,RoutedEventArgs e) { MessageBox.Show(TextHeader.Text); } hey guys I got the answer thanks for all the guys who ever was thinking of this question and here is the answer public Usercontrol() { InitializeComponent(); ButtonExport.Click += new RoutedEventHandler(ButtonExport_Click); } void ButtonExport_Click(object sender, RoutedEventArgs e) { MessageBox.Show(TextHeader.Text); }

更多推荐

动态创建按钮单击事件

本文发布于:2023-11-02 14:19:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552638.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单击   按钮   事件   动态

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!