45 lines
985 B
C#
45 lines
985 B
C#
|
||
using CommunityToolkit.Mvvm.ComponentModel;
|
||
|
||
namespace Cowain.Base.ViewModels;
|
||
|
||
/// <summary>
|
||
/// 视图页面模型基类
|
||
/// </summary>
|
||
public partial class PageViewModelBase : ObservableObject, IDisposable
|
||
{
|
||
/// <summary>
|
||
/// 页面标题
|
||
/// </summary>
|
||
public string? Title { get; set; }
|
||
|
||
public bool Disposed => _disposed;
|
||
private bool _disposed;
|
||
|
||
// 公开的 Dispose 方法(IDisposable 接口要求)
|
||
public void Dispose()
|
||
{
|
||
Dispose(true);
|
||
GC.SuppressFinalize(this);
|
||
}
|
||
|
||
// 虚方法:允许子类重写,清理自身资源
|
||
protected virtual void Dispose(bool disposing)
|
||
{
|
||
if (!_disposed)
|
||
{
|
||
if (disposing)
|
||
{
|
||
// 基类自身的托管资源清理(如命令、定时器等)
|
||
}
|
||
_disposed = true;
|
||
}
|
||
}
|
||
|
||
// 析构函数(非托管资源兜底)
|
||
~PageViewModelBase()
|
||
{
|
||
Dispose(false);
|
||
}
|
||
}
|