| 1234567891011121314151617181920212223242526272829303132333435 |
- 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();
- }
- }
- /// <summary>
- /// 执行与释放或重置非托管资源相关的应用程序定义的任务。
- /// </summary>
- public virtual void Dispose()
- {
- AutoCleanWindow_Unloaded(null, null);
- this.DataContext = null;
- }
- }
- }
|