English 中文(简体)
B. 随附的活动笔记
原标题:Change already attached event handler runtime

I have created a TextBox dynamically and attached a Tap event handler to it using:

control.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(OnClick1);

It works fine. But, now I want to change the event handler to point to some different method. I tried:

control.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(OnClick2);

但是,它仍然指向第一事件手。 i.e. OnClick1。 我可以做些什么来说明? 还有一种办法可以完全消除这一活动。

最佳回答

You need to remove the first handler first:

control.Tap -= OnClick1;
control.Tap += OnClick2;

(说明更简单地使用方法组别转换,而不是明确制造活动手。) 这样做是一样的,但可以读得更多。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签