WindowCloseCommand.cs 694 B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Input;
  8. namespace WpfStyleableWindow.StyleableWindow
  9. {
  10. public class WindowCloseCommand :ICommand
  11. {
  12. public bool CanExecute(object parameter)
  13. {
  14. return true;
  15. }
  16. #pragma warning disable 0067
  17. public event EventHandler CanExecuteChanged;
  18. #pragma warning restore 0067
  19. public void Execute(object parameter)
  20. {
  21. var window = parameter as Window;
  22. if (window != null)
  23. {
  24. window.Close();
  25. }
  26. }
  27. }
  28. }