Xamarin.forms Xamarin forms Prism如何在iOS项目中使用IEventAggregator

Xamarin.forms Xamarin forms Prism如何在iOS项目中使用IEventAggregator,xamarin.forms,prism,Xamarin.forms,Prism,我的问题是如何在Xamarin.Forms的iOS项目的类中使用IEventAggregator,来发布消息 将IEventAggregator作为构造函数参数传递似乎不起作用。似乎无法在iOS项目中解决依赖关系。那么,我如何解决iOS项目中IEventAggregator的依赖关系,以便在类中使用来发布 我正在使用Prism 6.3.0PrismApplication的容器是一个公共属性。因此,您可以访问容器以解决依赖关系,如: var ea = ((App)Application.Curre

我的问题是如何在Xamarin.Forms的iOS项目的类中使用
IEventAggregator
,来发布消息

IEventAggregator
作为构造函数参数传递似乎不起作用。似乎无法在iOS项目中解决依赖关系。那么,我如何解决iOS项目中
IEventAggregator
的依赖关系,以便在类中使用来发布


我正在使用Prism 6.3.0

PrismApplication的容器是一个公共属性。因此,您可以访问容器以解决依赖关系,如:

var ea = ((App)Application.Current).Container.Resolve<IEventAggregator>();
ea.GetEvent<SomeEvent>().Publish(somePayload);
var ea=((App)Application.Current).Container.Resolve();
ea.GetEvent().Publish(somePayload);

PrismApplication的容器是公共属性。因此,您可以访问容器以解决依赖关系,如:

var ea = ((App)Application.Current).Container.Resolve<IEventAggregator>();
ea.GetEvent<SomeEvent>().Publish(somePayload);
var ea=((App)Application.Current).Container.Resolve();
ea.GetEvent().Publish(somePayload);

我收到一个编译错误。我正在尝试使用您在iOS项目的我的类中编写的代码,错误是:“Application”是在当前上下文中无效的类型。该项目是一个没有任何功能的新项目,只是添加了prism。
应用程序
的类型为
App5.iOS.Application
,而该应用程序的类型为
App5.App
您不应该引用iOS应用程序。。。请确保您引用的是
Xamarin.Forms.Application
抱歉,我没有得到它。在哪一部分我不应该引用iOS应用程序?我写的代码和你写的一模一样。你从PrismApplication派生的应用程序与iOS无关…我提供的代码引用的是最终成为Xamarin.Forms.Application的应用程序。。。由于名称空间的原因,您在iOS项目中引用的应用程序类是错误的。有很多方法可以解决你的问题。。。1) 完全符合申请条件。2) 使用Application=Xamarin.Forms.Application添加
好的,它可以工作。代码类似于
var ea=((App)Xamarin.Forms.Application.Current).Container.Resolve()。非常感谢。我收到一个编译错误。我正在尝试使用您在iOS项目的我的类中编写的代码,错误是:“Application”是在当前上下文中无效的类型。该项目是一个没有任何功能的新项目,只是添加了prism。
应用程序
的类型为
App5.iOS.Application
,而该应用程序的类型为
App5.App
您不应该引用iOS应用程序。。。请确保您引用的是
Xamarin.Forms.Application
抱歉,我没有得到它。在哪一部分我不应该引用iOS应用程序?我写的代码和你写的一模一样。你从PrismApplication派生的应用程序与iOS无关…我提供的代码引用的是最终成为Xamarin.Forms.Application的应用程序。。。由于名称空间的原因,您在iOS项目中引用的应用程序类是错误的。有很多方法可以解决你的问题。。。1) 完全符合申请条件。2) 使用Application=Xamarin.Forms.Application添加
好的,它可以工作。代码类似于
var ea=((App)Xamarin.Forms.Application.Current).Container.Resolve()。谢谢。