using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Core
{
///
/// 弹窗基类
///
public class DialogViewModel : BindableBase, IDialogAware
{
public string? Title { get; set; }
public event Action? RequestClose;
///
/// 调用RequestClose
///
///
public void RaiseRequestClose(IDialogResult dialogResult)
{
RequestClose?.Invoke(dialogResult);
}
///
/// 是否关闭窗口
///
///
public bool CanCloseDialog()
{
return true;
}
///
/// 关闭时触发
///
public void OnDialogClosed()
{
OnDialogClosed(ButtonResult.OK);
}
public void OnDialogClosed(ButtonResult result)
{
RequestClose?.Invoke(new DialogResult(result));
}
public void OnDialogClosed(IDialogResult dialogResult)
{
RequestClose?.Invoke(dialogResult);
}
//public void OnDialogClosed() => OnDialogClosed(ButtonResult.OK);
///
/// 打开时触发
///
///
public virtual void OnDialogOpened(IDialogParameters parameters)
{
}
public bool IsNotBusy => !IsBusy;
private bool isBusy;
public bool IsBusy
{
get => isBusy;
set
{
isBusy = value;
RaisePropertyChanged();
RaisePropertyChanged(nameof(IsNotBusy));
}
}
public virtual async Task SetBusyAsync(Func func, string loadingMessage = null)
{
IsBusy = true;
try
{
await func();
}
finally
{
IsBusy = false;
}
}
}
}