2023-11-22 21:02:42 +08:00
|
|
|
|
using CPF.Controls;
|
|
|
|
|
using CPF.Toolkit.Dialogs;
|
2023-11-22 17:30:26 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace CPF.Toolkit
|
|
|
|
|
{
|
2023-11-22 21:02:42 +08:00
|
|
|
|
public class ViewModelBase : ObservableObject, IClosable, IDialog
|
2023-11-22 17:30:26 +08:00
|
|
|
|
{
|
2023-11-22 21:02:42 +08:00
|
|
|
|
event EventHandler<bool?> _close;
|
|
|
|
|
|
2023-11-22 17:30:26 +08:00
|
|
|
|
public IDialogService Dialog { get; set; }
|
2023-11-22 21:02:42 +08:00
|
|
|
|
|
|
|
|
|
event EventHandler<bool?> IClosable.Closable { add => this._close += value; remove => this._close -= value; }
|
|
|
|
|
|
|
|
|
|
protected void Close(bool? dialogResult = null)
|
|
|
|
|
{
|
|
|
|
|
if (this._close == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException();
|
|
|
|
|
}
|
|
|
|
|
this._close.Invoke(this, dialogResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void OnClose(ClosingEventArgs e) { }
|
|
|
|
|
|
|
|
|
|
void IClosable.OnClosable(object sender, ClosingEventArgs e) => this.OnClose(e);
|
2023-11-22 17:30:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|