MVVM light ViewModelLocator是否可以识别正在加载哪个视图然后动态生成视图模型?
public ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
//Find the current window/ user control loading
ContentControl control =
//Generate the View model dynamically
//Register to dynamically created view model
SimpleIoc.Default.Register<SelectedViewModel>();
}
答案 0 :(得分:1)
如果要避免ViewModelLocator编码切换到基于命名约定的框架,如MVVMCross。在MVVMCross中,您根本没有定位器,只需创建一个MyViewModel对象和一个MyView视图:框架根据名称约定匹配它们。