Show dialog with MVVM Light toolkit

后端 未结 4 444
粉色の甜心
粉色の甜心 2020-12-04 22:55

I have a ViewModel that needs to show a modal window (using ShowDialog()) on a button click. The ViewModel catches the click command, but I don\'t want to do

4条回答
  •  猫巷女王i
    2020-12-04 23:24

    You should use Messenger class. On the View register a message to show window, and then when you need to show it call Send method of Messenger class.

    You can do something like this:

        //do this in the code-behind file of your View
        Messenger.Default.Register(this, ShowWindow);
        
        private void ShowWindow(string message)
        {
            // your logic here
        }
        
        // In the ViewModel
        Messenger.Default.Send(“Some text”);
    

提交回复
热议问题