MVVM Light Toolkit 에서는 내장 Helper 클래스인 Messenger 를 이용해 ViewModel 과 View 간에 통신할 수 있습니다.
Window Code behind
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); Closing += (s, e) => ViewModelLocator.Cleanup(); Messenger.Default.Register<NotificationMessage>(this, (message) => { switch(message.Notification) { case "ShowTestWindow": { var testWindow = new TestWindow(); testWindow.Show(); break; } } }); } }
ViewModel
public class MainViewModel : ViewModelBase { #region [Command] ShowTestWindowCommand private RelayCommand _showTestWindowCommand; public RelayCommand ShowTestWindowCommand { get { return _showTestWindowCommand ?? (_showTestWindowCommand = new RelayCommand(() => Messenger.Default.Send(new NotificationMessage("ShowTestWindow")) )); } } #endregion }
MVVM Light WPF open new window
stack overflow
Open/Close View from ViewModel
stack overflow