c# - MVVM light ViewModelLocator是否有可能基于 View 动态生成 View 模型

标签 c# mvvm mvvm-light viewmodellocator

MVVM light ViewModelLocator是否可以识别正在加载的 View ,然后动态生成 View 模型?

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>();

}

My Project structure is given below

最佳答案

如果要避免ViewModelLocator编码,请切换到基于命名约定的框架,例如MVVMCross。在MVVMCross中,您根本没有定位器,只需创建一个MyViewModel对象和一个MyView View :该框架根据名称约定匹配它们。

关于c# - MVVM light ViewModelLocator是否有可能基于 View 动态生成 View 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44146423/

相关文章:

c# - 如何模拟 UserManager<IdentityUser>

c# - 访问库函数时 char** 的编码问题

c# - RelayCommand<PasswordBox> CanExecute 从不在 Windows 8.1 商店上运行,但在 WPF 上运行

win-universal-app - UWP Windows 10 应用程序在 Release模式下崩溃,但在 Debug模式下工作正常

c# - 在启动时设置按钮的 ToggleState 并检查状态

c# - 使用 FileWatcher 检测文件夹中是否创建了新文件

ios - 使用 RxSwift 链接登录操作

c# - WPF UI 未更新

c# - 从 ViewModel 更改标签内容 Prop

c# - 绑定(bind)进度条可见性 mvvm 不起作用