Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Prism Composite PresentationEvent激发两次_C#_Wpf_Prism - Fatal编程技术网

C# Prism Composite PresentationEvent激发两次

C# Prism Composite PresentationEvent激发两次,c#,wpf,prism,C#,Wpf,Prism,在我的基础设施中,我发布了一个事件 this.eventAggregator.GetEvent<ReportAddedEvent>().Publish(report); this.eventAggregator.GetEvent().Publish(报告); 报告是一个对象 在我的控制器中,我订阅此事件 this.eventAggregator.GetEvent<ReportAddedEvent>().Subscribe(this.OnReportAdded)

在我的基础设施中,我发布了一个事件

  this.eventAggregator.GetEvent<ReportAddedEvent>().Publish(report);
this.eventAggregator.GetEvent().Publish(报告);
报告是一个对象

在我的控制器中,我订阅此事件

  this.eventAggregator.GetEvent<ReportAddedEvent>().Subscribe(this.OnReportAdded);
this.eventAggregator.GetEvent().Subscribe(this.OnReportAdded);
我的问题是该事件触发了两次。在整个代码中没有其他地方发布事件,因此我确定事件不会在其他地方触发,并且我只能看到它触发一次


任何人都有问题的建议或解决方案,或者知道问题所在。

我认为问题在于代码

this.eventAggregator.GetEvent<ReportAddedEvent>().Subscribe(this.OnReportAdded);
this.eventAggregator.GetEvent().Subscribe(this.OnReportAdded);
要订阅ReportAddEvent,将执行两次


您应该检查(通过使用调试器和一行上的断点)它是否执行了多次。

我认为问题在于代码

this.eventAggregator.GetEvent<ReportAddedEvent>().Subscribe(this.OnReportAdded);
this.eventAggregator.GetEvent().Subscribe(this.OnReportAdded);
要订阅ReportAddEvent,将执行两次


您应该检查(通过使用调试器和行上的断点)它是否执行了多次。

订阅事件的代码可能被调用了两次。你应该检查一下,这救了我一天。我将给我的第一个孩子取名为杰霍夫。非常感谢,订阅活动的代码可能会被调用两次。你应该检查一下,这救了我一天。我将给我的第一个孩子取名为杰霍夫。感谢一个发生在我身上的事件,因为我在不同的ViewModels中调用了两次我订阅该事件的ViewModel实例。谢谢杰霍夫!这发生在我身上,因为我在不同的ViewModel中调用了两次订阅事件的ViewModel实例。谢谢杰霍夫!