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
  • 730,956
  • 141
  • 904
  • 1,278
ernest
  • 1,633
  • 2
  • 30
  • 48

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