_parameter.WeakSubscribe(() => _parameter.Value, HandleValueChanged);
我像上面一样使用WeakSubscribe。
我的情况是,值更改后,系统将添加一个新参数,而当前参数将退订该事件。
我发现了这个问题,但是没有用。
如果您使用以下方式订阅:
_token = thing.WeakSubscribe(() => parameter.Value, HandleValueChanged);
那么您可以使用以下方式退订:
_token.Dispose();
_token = null;
这将调用https://github.com/MvvmCross/MvvmCross/blob/v3.1/CrossCore/Cirrious.CrossCore/WeakSubscription/MvxWeakEventSubscription.cs#L91中的Dispose
代码:
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
RemoveEventHandler();
}
}
private void RemoveEventHandler()
{
if (!_subscribed)
return;
var source = (TSource) _sourceReference.Target;
if (source != null)
{
_sourceEventInfo.GetRemoveMethod().Invoke(source, new object[] {CreateEventHandler()});
_subscribed = false;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句