Mathias F
Mathias F

Reputation: 15891

Call a method on ShellViewModell from ModalDialog

I have a ShellViewModel that opens a ModalDialog window. The user enters some data in the ModalWindow and clicks a button. This should close the ModalWindow and execute a method in ShellViewModel.

I am already able to close the ModalDialog but have no Idea how to call the method ShowTables in ShellViewModel. How can it be called?

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

Upvotes: 0

Views: 45

Answers (1)

mvermef
mvermef

Reputation: 3914


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

Or use a EventAggregator Message based on the closure of the dialog... Which would be handled in the ShellViewModel in this case based on your indicated setup.

Upvotes: 1

Related Questions