How to close a UserControl View in mvvm-light?
I've craeted a sample with mainView and 2 other views (usercontrols). I've placed a button "close" on the child view and i want to close that view. there is a command atta开发者_开发问答ched to that button, and when close is pressed i ask the ViewModelLocator to clean it.
BUt- the view still being displayed.. What i'm doing wrong? How can i close a userControl view with mvvm-light?
private RelayCommand _closeCommand;
public RelayCommand CloseCommand
{
get
{
if (_closeCommand == null)
{
_closeCommand = new RelayCommand(()=>
ViewModelLocator.ClearAllChannels(),
);
}
return _closeCommand;
}
}
ViewModelLocator function:
public static void ClearAllChannels()
{
if (_allChannels != null)
{
_allChannels.Cleanup();
_allChannels = null;
}
}
The ViewModelLocator does not actually host your views. It just provides a way to look up the ViewModel that supports a particular view.
So you need to ask the control that hosts your views (probably a Window or Frame) to close them.
精彩评论