2

I have a child window that is used for logging in. Previously, a large portion of the code was in the Window's code behind. I refactored all of it to fit the MVVM model. Which it's all working, except I can't close the child window when it's done.

I've looked into how to accomplish this from the VM, but everything I've tried hasn't ended up working.

Any ideas?

Jonathan Leffler
  • 698,132
  • 130
  • 858
  • 1,229
ernest
  • 1,639
  • 2
  • 31
  • 46

1 Answers1

2

Add Finished event to view model. Call OnFinished method when you need to close.

public event EventHandler Finished;
protected void OnFinished()
{
    if (Finished != null)
        Finished(this, new EventArgs());
}

From code behind of child window subscribe to event and actually close the window.

ViewModel.Finished += (s, e) => Close();

See also

Creating an MVVM friendly dialog strategy

Community
  • 1
  • 1
pods
  • 96
  • 4