0

I have two Views (windows) and their associated ViewModels. The first one, ShellView and the second one, CreatePersonView. What I'd like to is when I click on a button in the ShellView it opens up the CreatePersonView in a new window. When this window get closed, the parent should execute some tasks.

Thanks for your help.

1 Answers1

1

You can achieve this with EventAggregator and Window Manager

Step 1: Invoke CreatePerson window on button click.

public void PersonClick() => _windowManager.ShowDialog(_createPersonVM);

WindowManager should be imported in the constructor of ShellViewModel.

Step 2: Continue task in Shell when CreatePersonView is closed. You need use event aggregator for this.

 public void CloseEvent() => _eventAggregator.PublishOnUIThread(new CloseMsg() {Message = "Hey closed"});

The ShellViewModel needs to subscribe to eventaggregator of CloseMsg (IHandle).

This will help you achieve your goal.

Let me know if you need further clarification. Can share the complete code.

Anu Viswan
  • 17,797
  • 2
  • 22
  • 51
  • Could you explain how to import the WindowManager in the constructor ? – Strangloss Apr 26 '18 at 19:25
  • hi, you can do as following in the constructor. [ImportingConstructor] public ShellViewModel(IWindowManager windowManager) { _windowManager = windowManager; } – Anu Viswan Apr 28 '18 at 03:58
  • @Anu Viswan: Could you please show the complete code for the example given? I am facing the same problem and lack understanding of how to get this "hook" done. – timunix Jan 11 '20 at 14:42