如何在ViewModel中获取绑定ContentView的服务?

时间:2018-05-08 07:36:59

标签: xamarin.forms prism

描述 1,我在views floder中创建名为LeftContent的ContentView,并创建名为LeftContentViewModel的viewmodel,然后使用“prism:ViewModelLocator.AutowireViewModel =" True"绑定他们 2,创建ITestInterface类并实现TestInterface,并在App类中注册 3,在LeftContentViewModel构造函数中,添加参数ITestInterface 4,runninng时,发生错误。代码和eception如下 非常感谢!

1 个答案:

答案 0 :(得分:0)

您的异常正好告诉您问题所在:

  

Unity.Exceptions.ResolutionFailedException:依赖项的解析失败,type ='System.Object',name ='PrismContentPage1'。

查看您的RegisterTypes,您只添加了服务注册,并注释了您的注册注册。另请注意,ViewModel应该只有一个构造函数。