我在棱镜中工作,CallerMember属性在我的代码中不能很好地工作。我有一个Close方法,想知道Close方法从哪里调用。通常,使用CallerMember属性标记的memberName参数应该收到调用方法名。但是订阅和取消订阅代码显示,这个eventAggregator有一些无效的参数。任何帮助都将不胜感激。
private void Close(bool isOKCommand,[CallerMemberName] string memberName = "")
{
this.eventAggregator.GetEvent<ShowWarningMessageEvent>().Unsubscribe(this.Close);
if (isOKCommand)
{
//Doing some operations;
}
}发布于 2013-12-03 21:04:36
你调用和使用EventAggregator的Unsubscribe方法的方式可能有问题,这就是你得到Invalid Arguments异常的原因。
取消订阅棱镜事件需要Subscribe方法返回的订阅令牌或您传递给Subscribe方法的回调委托。有关更多信息,请参阅MSDN
SubscriptionToken subscriptionToken = this.eventAggregator.GetEvent<ShowWarningMessageEvent>().Subscribe(<YourSubscribeMethod>);
this.eventAggregator.GetEvent<ShowWarningMessageEvent>().Unsubscribe(subscriptionToken);https://stackoverflow.com/questions/20347133
复制相似问题