WPF中的UserControl事件 [英] UserControl event in WPF

查看:526
本文介绍了WPF中的UserControl事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在WPF中制作一个应用程序,其中有一个窗口,其中有一个堆栈面板.现在,当我从数据库中获取学生列表时,有很多学生..现在,我创建了一个用户控件,该控件针对每个学生生成,并放置在stackpanel中!
现在,在该用户控件中,它填充有学生姓名",手机号码",并且有两个按钮,分别是编辑"和删除"..

现在窗口看起来像这样..

学生1编辑删除

学生2编辑删除


现在我只生成了一个字段,它被调用了很多次..现在我需要的是当我单击编辑"或删除按钮"时,应对其单击按钮的特定学生进行编辑或删除.....

请让我知道我该怎么做...

谢谢&问候,
Krunal Panchal

Hello everyone,

I am making one application in WPF in which there is a window inside which it has a stackpanel. Now when i fetch list of students from database there are many students.. now i have created one user control which is generated for each and every student and placed into stackpanel !!

Now in that user control it is populated with Student Name, Mobile Number and there are two buttons namely "Edit" and "Delete"..

Now the window looks like this..

Student 1 Edit Delete

Student 2 Edit Delete


now i have generated only one field and it is called many times .. now what i need is when i click Edit or Delete Button specific student on which the button is clicked should be edited or deleted.....

Please let me know how could i make this possible...

Thanks & Regards,
Krunal Panchal

推荐答案

使用标签.

如果您有许多对象作为Student(例如,student1,student2,...)

生成按钮时,设置buton =特定学生的标签.

例如:

Use tag.

If you have many objects as Student (For example student1, student2, ...)

Set the tag of buton = specific student when the buttons are being generated.

for example:

Edit1.Tag = student1;
Delete1.Tag = student1;

Edit2.Tag = student2;
Delete2.Tag = student2;



现在,当您单击编辑"或删除"时,便知道单击了哪个按钮.

在Button_Click事件中:



Now, when you click on edit or delete, then you know that which button is clicked.

In Button_Click event:

Student selectedItem = (Student)sender;


这篇关于WPF中的UserControl事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆