38 lines
870 B
C#
38 lines
870 B
C#
|
using System;
|
||
|
using DispenserCommon.Events;
|
||
|
using ReactiveUI;
|
||
|
|
||
|
namespace DispenserUI.ViewModels;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 可用于动态的切换页面是否显示的view model
|
||
|
/// </summary>
|
||
|
public abstract class DynamicViewModel : ViewModelBase
|
||
|
{
|
||
|
private bool _visible;
|
||
|
|
||
|
protected DynamicViewModel(EventType type = EventType.PageChanged)
|
||
|
{
|
||
|
EventBus<Type>.AddEventHandler(type, WhenPageChanged);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 动态控制是否显示
|
||
|
/// </summary>
|
||
|
public bool Visible
|
||
|
{
|
||
|
get => _visible;
|
||
|
set
|
||
|
{
|
||
|
_visible = value;
|
||
|
this.RaisePropertyChanged();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public virtual void WhenPageChanged(EventType type, Type data)
|
||
|
{
|
||
|
var me = GetType();
|
||
|
// 默认是当前是当前的data为当前ViewModel的类型
|
||
|
Visible = data == me;
|
||
|
}
|
||
|
}
|