event handlers in assemblies
来源:互联网 发布:国内外电视直播软件apk 编辑:程序博客网 时间:2024/05/01 00:22
When an event is handled by a pre-compiled assembly, you can use the short form of specifying just the event handler's method name if the method name is unique. MyXaml searches all object targets that have been registered with the parser using Add Target.
Passing An Event Target When Loading A Form
A typical usage is as follows:
public class Startup{ public void Start() { Parser p=new Parser(); Form form=(Form)p.LoadForm("app.myxaml", "AppMainForm", this, null); Application.Run(form); } public void OnClick(object sender, EventArgs e) { // ... event handler }}
In the above example, an event target is automatically added to the parser's event target collection because the Startup class is specified in the third parameter ("this") when loading the form. In the markup, a typical usage would be:
<Button Click="OnClick"/>
Pre-registering Event Targets
A slightly more complicated example illustrates pre-registering an event target:
public class Startup{ public void Start() { MyOtherClass c=new MyOtherClass(); Parser p=new Parser(); p.AddTarget(c); Form form=(Form)p.LoadForm("app.myxaml", "AppMainForm", this, null); Application.Run(form); } public void OnClick(object sender, EventArgs e) { // ... event handler }}public class MyOtherClass{ public void OnDoubleClick(object sender, EventArs e) { // ... event handler }}
In the markup, a typical usage would be:
<Button Click="OnClick" DoubleClick="OnDoubleClick"/>
In the above example, the parser inspects both targets to resolve the event handler.
Specifying A Handler In A Specific Instance
For complex programs, you will usually find yourself wanting to specify the instance that is to handle the event. The format for this markup is:
<Button Click="{MyInstance.OnClick}"/>
IMPORTANT: The instance "MyInstance" is resolved by inspecting the definition list not the event target list.
You can either use Add Reference to specify the definition in the imperative code:
public class Startup{ public void Start() { MyOtherClass c=new MyOtherClass(); Parser p=new Parser(); p.AddReference("MyInstance", c); Form form=(Form)p.LoadForm("app.myxaml", "AppMainForm", this, null); Application.Run(form); }}...
or isntantiate the class declaratively using the def:Name construct to add the instance to the definition lis:
<MyOtherClass def:Name="MyInstance"/><Button Click="{MyInstance.OnClick}"/>
Late binding is supported using this form of event wire-ups. For example, the following markup works equally well:
<Button Click="{MyInstance.OnClick}"/><MyOtherClass def:Name="MyInstance"/>
- event handlers in assemblies
- ANDROID Event Handlers
- 什么是event handlers ?
- Spring - Spring Data REST - Prevent The Methods in Event Handlers Be Triggered Twice
- Javascript Events and Event Handlers
- Completion Handlers in Swift
- #734 – 在触摸事件中识别不同的手指(Recognizing Different Fingers in Touch Event Handlers)
- activiti学习笔记10--Event handlers--20170705
- HTTP Handlers in ASP.NET
- Handlers
- 7-1 重写事件处理函数(Reimplementing Event Handlers)
- Effective C#之Item 35:Prefer Overrides to Event Handlers
- Solving the Problem with Events: Weak Event Handlers
- SharePoint 2007中所有的Event Handlers事件清单
- Understanding and Using Assemblies and Namespaces in .NET
- 怎样在windows media center里面调试add-in assemblies
- Using CoCreateObjectDotNet to Access and Use .NET Assemblies in InstallScript
- How To Load .NET Assemblies In A PowerShell Session
- 写了一个俄罗斯
- 我的第一个独立创作的企业级作品——LV网站
- Using MyXaml on the Compact Framework
- 分析:BPM与SOA之间的区别及联系
- [转载]Windows下架设Subversion服务器
- event handlers in assemblies
- 移植Qtopia4到S3C2440
- BOM关系表
- DB2的联合查询
- CMMI for DEV v1.2 Chapter 4(结束)
- 如何取得数据库对象的脚本信息
- javascript对下拉列表框(select)的操作
- 使用 ASP.NET Login 控件的高级功能
- 全面认识UML类图元素