I have a ViewModel with some internal code that need to close the window that my viewmodel is bound to. So far I have:
MyWindow.xaml.cs
public class MyWindow : Window
{
public MyWindow()
{
InitializeComponent();
DataContext = new MyVM(this);
}
}
MyVM.cs
public class MyVM
{
public MyVM(MyWindow owner)
{
Owner = owner;
}
public MyWindow Owner { get; }
public void SomeAction()
{
Owner.Close();
}
}
This works perfectly, but I created a dependency between MyVM with My Window that is not needed, or at least not intended.
So here is my question: Is there a way to Close a window without has directly pass the reference of the window to the view model?
UPDATE - Possible Duplicate:
Different of the question and the accepted answer, I don't have any command bind I cannot pass the window as command parameter.
The possible duplicate question show some vm code binded as command to a button. I'm not trying to execute Window.Close() inside a command bind scope.