using System; using System.Windows.Controls; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Messaging; using Muchinfo.MTPClient.Infrastructure.Helpers; namespace Muchinfo.MTPClient.Infrastructure.Windows { public class UnloadCleanWindow : UserControl, IDisposable { public UnloadCleanWindow() { this.Unloaded += AutoCleanWindow_Unloaded; } protected void AutoCleanWindow_Unloaded(object sender, System.Windows.RoutedEventArgs e) { MessengerHelper.DefaultUnregister(this); var viewModel = this.DataContext as ViewModelBase; if (viewModel != null) { viewModel.Cleanup(); } } /// /// 执行与释放或重置非托管资源相关的应用程序定义的任务。 /// public virtual void Dispose() { AutoCleanWindow_Unloaded(null, null); this.DataContext = null; } } }