开发者

How to clean the event from all attached methods

I have a control, for example Button. I want to clean up event OnClick, but I don't know how much methods it calls and don't know names of methods (like: btn.OnClickClear();). I found this link: http://msdn.microsoft.com/en-us/library/bb979826%28v=vs.95%29.aspx but don't understand how to implement it in Silverlight.开发者_运维问答


I am using Silverlight 4. Thanks


Not really sure if you mean this; but when you add an event listener on your Button like this:

btnName.Click += new System.Windows.RoutedEventHandler(OnClick);

void OnClick(object sender, System.Windows.RoutedEventArgs e)
{
  // Handle event
}

You can remove it like this:

btnName.Click -= new System.Windows.RoutedEventHandler(OnClick);

From inside the Button class you can set the Click event to null like, which removes all event listeners I think.

this.Click = null;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜