[英]How can I reuse the same view with different ViewModel in wpf prism?
[英]When using Prism on Xamarin, how can I warn if the names on the View, and ViewModel don't match?
Prism使用MVVM样式约定命名将View绑定到Xamarin应用程序上的ViewModel。
我最近更改了一些演示代码,并花了很多时间调试后才意识到页面名称与视图不匹配。
如何启用日志记录或预编译器警告,指出存在这种差异?
在View的Prism Core中,ViewModelLocationProvider负责为View定位ViewModel。 您可以在此处查看其实施方式。 如果要覆盖默认行为并注入自己的日志记录,则可以将其用作模板并调用ViewModelLocationProvider. SetDefaultViewTypeToViewModelTypeResolver(YourCustomerLocatorFunctionHere)
ViewModelLocationProvider. SetDefaultViewTypeToViewModelTypeResolver(YourCustomerLocatorFunctionHere)
在App.OnInitialized
。
至于任何预编译警告,您将自己在那里编写工具。
要增加Dan的响应,可以使用Container.RegisterTypeForNavigation<View, ViewModel>()
方法绕过命名约定,并直接向View注册ViewModel。 这也更快,因为将不使用反射来定位VM。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.