从ModalDialog调用ShellViewModell上的方法

时间:2015-03-07 21:41:52

标签: c# wpf mvvm caliburn.micro

我有一个打开ModalDialog窗口的ShellViewModel。用户在ModalWindow中输入一些数据并单击按钮。这应该关闭ModalWindow并在ShellViewModel中执行一个方法。

我已经能够关闭ModalDialog但是没有想法如何在ShellViewModel中调用方法ShowTables。它怎么称呼?

ShellViewModel

namespace SQLInserter
{

     using Caliburn.Micro;
    using System.ComponentModel.Composition;
    using System.Dynamic;
    using System.Windows.Controls.Primitives;

          [Export(typeof(IShell))]
        public class ShellViewModel : Screen, IShell
        {
              readonly IWindowManager windowManager;

              [ImportingConstructor]
              public ShellViewModel(IWindowManager windowManager)
              {
                  this.windowManager = windowManager;
              }

            /// <summary>
            /// this needs to be called after 
            //  TryClose(); in ConnnectionViewModel.Connect() is executed
            /// </summary>
            public void ShowTables()
            {

            }

            public void ShowConnectiom()
            {
             windowManager.ShowDialog(new ConnectionViewModel(), "Connection");
            }
        }
    }

ConnectionViewModel

using Caliburn.Micro;
using System.Diagnostics;
using System.Linq;

namespace SQLInserter
{
    public class ConnectionViewModel : Screen
    {
        public ConnectionViewModel()
        {
        }

        public void Connect()
        {
            TryClose();
        }
    }
}

1 个答案:

答案 0 :(得分:1)


public void ShowConnection(){
  var connvm = new ConnectionViewModel();

   IDictionary settings = new Dictionary();
            settings["WindowStartupLocation"] = WindowStartupLocation.CenterScreen;
  //Does something with the connvm object, which allows 
  //continued process once dialog is closed.
  windowManager.ShowDialog(connvm, null,settings);  

  if( connvm != null && connvm.Connected){
     ShowTables();
  }
}

或者根据对话框的关闭使用EventAggregator消息...在这种情况下,将根据您指示的设置在ShellViewModel中处理。