CPF/CPF.Toolkit/ViewModelBase.cs

31 lines
838 B
C#
Raw Normal View History

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
{
public class ViewModelBase : ObservableObject, IClosable, IDialog
2023-11-22 17:30:26 +08:00
{
event EventHandler<bool?> _close;
2023-11-22 17:30:26 +08:00
public IDialogService Dialog { get; set; }
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
}
}