CloseWindowCommand.cs 519 B

1234567891011121314151617181920212223
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Input;
  4. namespace HandyControl.Interactivity;
  5. public class CloseWindowCommand : ICommand
  6. {
  7. public bool CanExecute(object parameter) => true;
  8. public void Execute(object parameter)
  9. {
  10. if (parameter is DependencyObject dependencyObject)
  11. {
  12. if (Window.GetWindow(dependencyObject) is { } window)
  13. {
  14. window.Close();
  15. }
  16. }
  17. }
  18. public event EventHandler CanExecuteChanged;
  19. }