WindowMaximizeCommand.cs 963 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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 WindowMaximizeCommand :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. if(window.WindowState == WindowState.Maximized)
  25. {
  26. window.WindowState = WindowState.Normal;
  27. }
  28. else
  29. {
  30. window.WindowState = WindowState.Maximized;
  31. }
  32. }
  33. }
  34. }
  35. }