WPF MVVM: How to close a window

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

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


21条回答
  •  温柔的废话
    2020-12-04 09:01

    Very clean and MVVM way is to use InteractionTrigger and CallMethodAction defined in Microsoft.Interactivity.Core

    You will need to add a new namespace as below

    xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
    

    You will need the Microsoft.Xmal.Behaviours.Wpf assembly and then the below xaml code will work.

    
    

    You don't need any code behind or anything else and can also call any other method of Window.

提交回复
热议问题