zoukankan      html  css  js  c++  java
  • 轻量级MVVM框架Stylet介绍:(6) WindowManager

    在传统的View-frist方式中,如果想要显示了一个新的Window或Dialog,需要创建一个View的实例,并且调用.Show()或.ShowDialog()方法。

    在ViewModel-first方式中,不能直接与Views交互,WindowManager解决了这个问题,只需要调用IWindowManager.ShowWindow(someViewModel)就可以调用ViewModel,发现其View,实例化并显示。

    class SomeViewModel
    {
       private IWindowManager windowManager;
       public SomeViewModel(IWindowManager windowManager)
       {
          this.windowManager = windowManager;
       }
     
       public void ShowAWindow()
       {
          var viewModel = new OtherViewModel();
          this.windowManager.ShowWindow(viewModel);
       }
     
       public void ShowADialog()
       {
          var viewModel = new OtherViewModel();
          bool? result = this.windowManager.ShowDialog(viewModel);
          // result holds the return value of Window.ShowDialog()
          if (result.GetValueOrDefault(true))
          {
             // DialogResult was set to true
          }
       }
    }
    

    很优雅也很简单!此外,引入IWindowMmanager使得测试更容易。

    要关闭Window或Dialog,使用Screen.RequestClose,如下所示:

    class ViewModelDisplayedAsWindow
    {
       // Called by pressing the 'close' button
       public void Close()
       {
          this.RequestClose();
       }
    }
     
    class ViewModelDisplayedAsDialog
    {
       // Called by pressing the 'OK' button
       public void CloseWithSuccess()
       {
          this.RequestClose(true);
       }
    }
    
  • 相关阅读:
    第01组 Beta冲刺(2/4)
    第01组 Beta冲刺(1/4)
    第01组 Alpha事后诸葛亮
    第01组 Alpha冲刺(4/4)
    第01组 Alpha冲刺(3/4)
    第01组 Alpha冲刺(2/4)
    第01组 Alpha冲刺(1/4)
    提高回顾与个人总结
    软件工程结对作业博客
    软件工程第一次阅读作业
  • 原文地址:https://www.cnblogs.com/qouoww/p/15797026.html
Copyright © 2011-2022 走看看