2017-10-13 97 views
0

使用IEventAggregator我的问题是如何利用IEventAggregator一个类里面Xamarin.Forms iOS的项目发布的消息。Xamarin形式棱镜我怎么能在iOS的项目

薪火IEventAggregator的构造函数的参数似乎并不工作。看起来依赖不能在iOS项目中解决。那么如何解决iOS项目中IEventAggregator的依赖关系,以便我可以在类中使用它来发布。

我正在使用棱镜6.3.0

回答

1

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

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

我收到了编译错误。我试图使用你在iOS项目中编写的代码,错误是:'Application'是一种在当前上下文中无效的类型。该项目是没有任何功能一个新的项目,只是增加prism.The'Application'的类型是App5.iOS.Application'的'和App的类型为'App5.App' – Dimitris

+0

你不应该被引用的iOS应用程序。 ..确保你引用的'Xamarin.Forms.Application' –

+0

对不起,我没有得到它。哪一部分我不应该引用iOS应用程序?我写了你写的代码。 – Dimitris