95 lines
2.2 KiB
C#
95 lines
2.2 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// 弹窗基类
|
|
/// </summary>
|
|
public class DialogViewModel : BindableBase, IDialogAware
|
|
{
|
|
public string? Title { get; set; }
|
|
|
|
public event Action<IDialogResult>? RequestClose;
|
|
|
|
/// <summary>
|
|
/// 调用RequestClose
|
|
/// </summary>
|
|
/// <param name="dialogResult"></param>
|
|
public void RaiseRequestClose(IDialogResult dialogResult)
|
|
{
|
|
RequestClose?.Invoke(dialogResult);
|
|
|
|
}
|
|
/// <summary>
|
|
/// 是否关闭窗口
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool CanCloseDialog()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭时触发
|
|
/// </summary>
|
|
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);
|
|
|
|
|
|
/// <summary>
|
|
/// 打开时触发
|
|
/// </summary>
|
|
/// <param name="parameters"></param>
|
|
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<Task> func, string loadingMessage = null)
|
|
{
|
|
IsBusy = true;
|
|
try
|
|
{
|
|
await func();
|
|
}
|
|
finally
|
|
{
|
|
IsBusy = false;
|
|
}
|
|
}
|
|
}
|
|
}
|