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;}#main-content .dfd-content-wrap {margin: 0px;} #main-content .dfd-content-wrap > article {padding: 0px;}@media only screen and (min-width: 1101px) {#layout.dfd-portfolio-loop > .row.full-width > .blog-section.no-sidebars,#layout.dfd-gallery-loop > .row.full-width > .blog-section.no-sidebars {padding: 0 0px;}#layout.dfd-portfolio-loop > .row.full-width > .blog-section.no-sidebars > #main-content > .dfd-content-wrap:first-child,#layout.dfd-gallery-loop > .row.full-width > .blog-section.no-sidebars > #main-content > .dfd-content-wrap:first-child {border-top: 0px solid transparent; border-bottom: 0px solid transparent;}#layout.dfd-portfolio-loop > .row.full-width #right-sidebar,#layout.dfd-gallery-loop > .row.full-width #right-sidebar {padding-top: 0px;padding-bottom: 0px;}#layout.dfd-portfolio-loop > .row.full-width > .blog-section.no-sidebars .sort-panel,#layout.dfd-gallery-loop > .row.full-width > .blog-section.no-sidebars .sort-panel {margin-left: -0px;margin-right: -0px;}}#layout .dfd-content-wrap.layout-side-image,#layout > .row.full-width .dfd-content-wrap.layout-side-image {margin-left: 0;margin-right: 0;}