如何从它使用一个lambda EX pression事件退订? [英] How to unsubscribe from an event which uses a lambda expression?

查看:154
本文介绍了如何从它使用一个lambda EX pression事件退订?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code,让图形用户界面响应集合中的变化。

I have the following code to let the GUI respond to a change in the collection.

myObservableCollection.CollectionChanged += ((sender, e) => UpdateMyUI());

首先是一个很好的办法做到这一点?

First of all is this a good way to do this?

二:什么是code从这个事件退订?它是相同的,但与 - =(然后完整的匿名方法了)

Second: what's the code to unsubscribe from this event? Is it the same but with -= (and then the complete anonymous method again)?

推荐答案

如果你需要从事件退订,你需要一个实例化的参考。不幸的是,这意味着你不能使用特定的语法。

If you need to unsubscribe from an event, you need an instanced reference. Unfortunately, that means you can't use that particular syntax.

这篇关于如何从它使用一个lambda EX pression事件退订?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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