borepin/Borepin/Borepin/DialogModel/ConfirmDialogModel.cs

86 lines
2.1 KiB
C#
Raw Normal View History

2021-01-27 01:04:08 +01:00
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Windows.Input;
namespace Borepin.DialogModel
{
public class ConfirmDialogModel : BindableBase, IDialogAware
{
2021-01-29 22:54:35 +01:00
private object _Instance;
2021-01-27 01:04:08 +01:00
public ConfirmDialogModel()
{
ConfirmCommand = new DelegateCommand(ConfirmCommandExecute);
AbortCommand = new DelegateCommand(AbortCommandExecute);
}
#region Properties
private string _Title;
public string Title
{
get => _Title;
set => SetProperty(ref _Title, value);
}
private string _Message;
public string Message
{
get => _Message;
set => SetProperty(ref _Message, value);
}
#endregion
#region Commands
private ICommand _ConfirmCommand;
public ICommand ConfirmCommand
{
get => _ConfirmCommand;
set => SetProperty(ref _ConfirmCommand, value);
}
private void ConfirmCommandExecute()
{
2021-01-29 22:54:35 +01:00
IDialogParameters parameters = new DialogParameters()
{
{ "result", "confirm" },
{ "instance", _Instance }
};
RequestClose(parameters);
2021-01-27 01:04:08 +01:00
}
private ICommand _AbortCommand;
public ICommand AbortCommand
{
get => _AbortCommand;
set => SetProperty(ref _AbortCommand, value);
}
private void AbortCommandExecute()
{
RequestClose(new DialogParameters { { "abort", true } });
}
#endregion
public event Action<IDialogParameters> RequestClose;
public bool CanCloseDialog()
{
return true;
}
public void OnDialogClosed()
{
}
public void OnDialogOpened(IDialogParameters parameters)
{
Title = parameters.GetValue<string>("title");
Message = parameters.GetValue<string>("message");
2021-01-29 22:54:35 +01:00
_Instance = parameters.GetValue<object>("instance");
2021-01-27 01:04:08 +01:00
}
}
}