xamarin.forms - 在 XAML 中绑定到绑定定位器不起作用
问题描述
我有一个使用服务定位器模式的带有 MvvmLight 的 Xamarin Forms 应用程序。ViewModelServiceLocator 本身是一个静态类,可以访问注册了所有依赖项的 Autofac 容器。对于每个 VM,都有静态属性:
public static AboutViewModel AboutVm => ServiceLocator.Current.GetInstance<AboutViewModel>();
我在我的应用程序中设置了定位器,资源如下:
<presentation:ViewModelLocator x:Key="Locator" />
在我页面上的 xaml 中:
BindingContext="{Binding AboutVm, Source={StaticResource Locator}}"
但是永远不会调用定位器。但它确实有效,当我在后面的代码中设置它时
BindingContext = ViewModelLocator.AccountListVm;
我错过了资源定义还是什么?
解决方案
推荐阅读
- angular - Angular 8 + IE 11:遗漏了一些 polyfill
- python - 在 PySpark 的 DataFrame 列中存储 DenseVector
- c# - 在 UWP 中从后台线程访问 UI 的正确方法
- php - 在 laravel 中发送电子邮件的最大收件人数是多少?
- python - 一旦触发意图,如何从 Python Webhook 发送多个延迟响应?
- twitter-bootstrap - Bootstrap 4:导航栏品牌左侧,链接中心,其他链接右侧
- perl - 奇怪的“使用未初始化的值”,正则表达式错误
- blockchain - 在虚拟机上安装超级账本结构对等体
- kubernetes - 如何使 Horizontal Pod Autoscaler 按百分比减少阈值缩小 pod 副本?
- python - 从 apache 日志中删除 2 次后获取 IP 的正则表达式