开发者

How to clean the event from all attached methods

开发者 https://www.devze.com 2023-02-10 07:23 出处:网络
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: htt

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

精彩评论

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