【问题标题】:How can i obtain service in ViewModel which binding a ContentView?如何在 ViewModel 中获取绑定 ContentView 的服务?
【发布时间】:2018-05-08 21:30:19
【问题描述】:

说明 1、我在views flder中创建了名为LeftContent的ContentView,并创建了名为LeftContentViewModel的viewmodel,然后使用“prism:ViewModelLocator.AutowireViewModel="True"绑定它们 2、创建ITestInterface类并实现TestInterface,并在App类中注册 3、在 LeftContentViewModel 构造函数中,添加参数 ITestInterface 4、运行时出现错误。代码和接收如下 非常感谢!

【问题讨论】:

  • 尝试从 App.cs 文件中的 RegisterType 方法中删除评论 containerRegistery.RegisterForNavigation()跨度>

标签: xamarin.forms prism


【解决方案1】:

您的异常准确地告诉您问题所在:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-19
    • 2015-08-20
    • 1970-01-01
    • 2015-07-09
    • 2018-08-08
    • 2016-10-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多