Files
WCS/Cowain.Base/ViewModels/PageViewModelBase.cs
2026-03-02 09:08:20 +08:00

45 lines
985 B
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}
}