如何在动态添加的用户控件上引发鼠标事件? [英] How to raise a mouse event on a dynamically added user control?

查看:72
本文介绍了如何在动态添加的用户控件上引发鼠标事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助,我需要知道下周我的学校考试!!!



我在WPF创建一个电子邮件客户端,到目前为止我有一个列表与LT;>使用消息,为每条消息创建一个用户控件,其中包含唯一标记(1,2,3,..)和表单内的数据。用户控件是在包装面板中动态添加的,具体取决于消息的数量。



这样的东西:

http://wscont2.apps.microsoft.com/winstore/1x/d1b21d52 -3c46-4eef-b118-c30109053170 / Screenshot.287867.1000003.jpg [ ^ ]



我想在用户控件上引发一个事件例如,用来自用户控件的数据打开一个更大的窗口。



如果我创建了一些自定义事件,我应该如何提升事件,因为我需要比较在主窗口中创建的用户控件的标记,以便它匹配并打开正确的窗口?

解决方案

如果您发布了生成动态控件的代码,那么它可能会有所帮助;然而,连接活动非常简单。



例如你可以这样做:



 MyUserControl ctl =  new  MyUserContro(); 
ctl.MouseRaisedEvent + = new ...





并且在您的用户控件中,您具有公开事件的属性。一个例子是 http://stackoverflow.com/questions/6192739/how-do-i-raise-an-event-in-a-usercontrol-and-catch-it-in-mainpage [ ^ ]


Please help, i need this to know for my school exam next week!!!

I am creating an Email Client in WPF, so far i have a List<> with messages, for each message is created a user control with a unique tag(1,2,3,..) and data inside the form. The user controls are added dynamically in a wrap panel depends on the number of messages.

Something like this:
http://wscont2.apps.microsoft.com/winstore/1x/d1b21d52-3c46-4eef-b118-c30109053170/Screenshot.287867.1000003.jpg[^]

I want to raise an event on the user control, for example open a bigger window with the data from the user control.

How should i raise the event, should i create somekind of custom event, becose i need to compare the tag of the usercontrol created in main window so it matches and opens the correct window?

解决方案

It would likely help if you posted the code you have for generating the dynamic controls; however, wiring up the events is pretty simple.

For example you can do something like this:

MyUserControl ctl = new MyUserContro();
ctl.MouseRaisedEvent += new ...



and in your user control you have properties to expose the events. An example is at http://stackoverflow.com/questions/6192739/how-do-i-raise-an-event-in-a-usercontrol-and-catch-it-in-mainpage[^]


这篇关于如何在动态添加的用户控件上引发鼠标事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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