2014-01-14 226 views

回答

6

如果您申请使用类似:

_token = thing.WeakSubscribe(() => parameter.Value, HandleValueChanged); 

那么你可以取消使用:

_token.Dispose(); 
_token = null; 

这就要求在https://github.com/MvvmCross/MvvmCross/blob/v3.1/CrossCore/Cirrious.CrossCore/WeakSubscription/MvxWeakEventSubscription.cs#L91Dispose代码:

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; 
     } 
    } 
+0

如果这个“没有按” t工作“,然后请考虑添加复制问题的代码 - 最好是一个块有人可以阅读和运行的代码(请参阅http://msmvps.com/blogs/jon_skeet/archive/2010/08/29/writing-the-perfect-question.aspx)。 – Stuart

+0

它工作正常。非常感谢。 – user3089631