1

I have a LoginWindows, that run in startup.

I have a enterButton ,when click it, send a parametr to mainwindows and show it then hide self.

   public RelayCommand EnterCommand { get; set; }
   ...
    public LoginViewModel()
    {
        EnterCommand = new RelayCommand(() => Enter());

    }

    private object Enter()
    {
     //Show MainWndow
     }

What is the best way to open a new window from the viewmodel in mvvmLight?

4

1 回答 1

1

这是有用的答案。https://stackoverflow.com/a/16994523/970404

概念:

  • 向 SimpleIoC 注册多个 VM 并使用 GetInstance(...) 请求它们。
  • 使用自定义消息类型 OpenWindowMessage 的 Messenger 类使用
  • 从遵循 MVVM 原则的父 VM 打开模态/非模态窗口
  • 在窗口之间传递数据(仅显示在 NonModal 中)

重要的提示:

此示例中用于从模态窗口设置非 DP DialogResult 的方法不是 MVVM 友好的,因为它使用代码隐藏在 Window.Closing 事件上设置 DialogResult 属性,这应该避免(如果需要“可测试”) . 我首选的方法有点长,并且在此处有很好的记录(问答混合)。因此,为什么我为了这个样本而忽略了它。

于 2013-07-17T04:26:15.843 回答