12345678910111213141516171819202122232425262728293031323334353637 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- namespace FWindSoft.Wpf
- {
- public static class WindowExtension
- {
- private static PropertyInfo m_IsDisposedPropertyInfo;
- /// <summary>
- /// 判断窗体是否释放
- /// </summary>
- /// <param name="window"></param>
- /// <returns></returns>
- public static bool IsDisposed(this System.Windows.Window window)
- {
- if (window == null)
- return true;
- if (m_IsDisposedPropertyInfo == null)
- {
- var type = typeof(System.Windows.Window);
- m_IsDisposedPropertyInfo=type.GetProperty("IsDisposed", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
- }
- if (m_IsDisposedPropertyInfo != null)
- {
- return (bool)m_IsDisposedPropertyInfo.GetValue(window);
- }
- return true;
- }
- }
- }
|