WindowExtension.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. namespace FWindSoft.Wpf
  9. {
  10. public static class WindowExtension
  11. {
  12. private static PropertyInfo m_IsDisposedPropertyInfo;
  13. /// <summary>
  14. /// 判断窗体是否释放
  15. /// </summary>
  16. /// <param name="window"></param>
  17. /// <returns></returns>
  18. public static bool IsDisposed(this System.Windows.Window window)
  19. {
  20. if (window == null)
  21. return true;
  22. if (m_IsDisposedPropertyInfo == null)
  23. {
  24. var type = typeof(System.Windows.Window);
  25. m_IsDisposedPropertyInfo=type.GetProperty("IsDisposed", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
  26. }
  27. if (m_IsDisposedPropertyInfo != null)
  28. {
  29. return (bool)m_IsDisposedPropertyInfo.GetValue(window);
  30. }
  31. return true;
  32. }
  33. }
  34. }