Blog categories

Comments

[WPF, MVVM Light] WPF MVVM Light Toolkit에서 새 창 열기

[WPF, MVVM Light] WPF MVVM Light Toolkit에서 새 창 열기

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
}

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

div#stuning-header .dfd-stuning-header-bg-container {background-color: #3f3f3f;background-size: cover;background-position: top center;background-attachment: initial;background-repeat: no-repeat;}#stuning-header div.page-title-inner {min-height: 350px;}