61 lines
1.9 KiB
C#
61 lines
1.9 KiB
C#
using Prism.Commands;
|
||
using Prism.Mvvm;
|
||
using System;
|
||
|
||
namespace DeviceEditModule.ViewModels
|
||
{
|
||
/// <summary>
|
||
/// 弹窗管理器中单个 Tab 项的 ViewModel。
|
||
/// 由 <see cref="DialogMangerViewModel"/> 在收到 AddDialogTabEvent 时创建,
|
||
/// 通过构造函数注入选中/关闭的回调,保持与父 ViewModel 的低耦合。
|
||
/// </summary>
|
||
public class DialogTabItemVM : BindableBase
|
||
{
|
||
#region 属性
|
||
|
||
private string _title = string.Empty;
|
||
/// <summary>Tab 标签页上显示的标题。</summary>
|
||
public string Title
|
||
{
|
||
get => _title;
|
||
set => SetProperty(ref _title, value);
|
||
}
|
||
|
||
private object? _content;
|
||
/// <summary>Tab 内容区域(通常为 UserControl 实例)。</summary>
|
||
public object? Content
|
||
{
|
||
get => _content;
|
||
set => SetProperty(ref _content, value);
|
||
}
|
||
|
||
private bool _isSelected;
|
||
/// <summary>是否为当前激活 Tab(用于切换选中态样式)。</summary>
|
||
public bool IsSelected
|
||
{
|
||
get => _isSelected;
|
||
set => SetProperty(ref _isSelected, value);
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 命令
|
||
|
||
/// <summary>点击 Tab 标题激活该 Tab。</summary>
|
||
public DelegateCommand SelectCommand { get; }
|
||
|
||
/// <summary>点击 Tab 上的 × 关闭并移除该 Tab。</summary>
|
||
public DelegateCommand CloseCommand { get; }
|
||
|
||
#endregion
|
||
|
||
/// <param name="onSelect">父 VM 提供的激活回调。</param>
|
||
/// <param name="onClose">父 VM 提供的关闭回调。</param>
|
||
public DialogTabItemVM(Action<DialogTabItemVM> onSelect, Action<DialogTabItemVM> onClose)
|
||
{
|
||
SelectCommand = new DelegateCommand(() => onSelect(this));
|
||
CloseCommand = new DelegateCommand(() => onClose(this));
|
||
}
|
||
}
|
||
}
|