Strangloss
Strangloss

Reputation: 5

Caliburn.micro open window by clicking button

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.

Upvotes: 0

Views: 893

Answers (1)

Anu Viswan
Anu Viswan

Reputation: 18173

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.

Upvotes: 1

Related Questions