AppHelper.cs 522 B

123456789101112131415161718192021222324
  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. namespace WpfApp29
  8. {
  9. public class AppHelper
  10. {
  11. public static T? GetWindowAtType<T>() where T: Window
  12. {
  13. foreach (var unknownWindoew in App.Current.Windows)
  14. {
  15. if (unknownWindoew is T window)
  16. {
  17. return window;
  18. }
  19. }
  20. return null;
  21. }
  22. }
  23. }