WPF MVVM: How to close a window

后端 未结 21 1753
后悔当初
后悔当初 2020-12-04 08:19

I have a Button that closes my window when it\'s clicked:


21条回答
  •  不思量自难忘°
    2020-12-04 09:00

    You can do it without code behind. Create command, in Execute method call "Save" method on viewmodel and after that call close method on edit window, which you can pass to the command by parameter:

    public void Execute(object parameter)
    {
        _mainViewModel.SaveSomething();
        var editWindow = parameter as MyEditWindow;
        editWindow?.Close();
    }
    

    Save&Close button XAML:

提交回复
热议问题