From 2f12b52fc28d33ec37995e10fcdf38d423bde55e Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Mon, 13 Nov 2023 10:37:19 +0330 Subject: [PATCH] Support for BindPropertyChanged --- .../BaseViewModel.cs | 33 ++++++++++++++++++- .../EasyMicroservices.UI.Core.Mvvm.csproj | 2 +- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/CSharp/EasyMicroservices.UI.Core.Mvvm/BaseViewModel.cs b/src/CSharp/EasyMicroservices.UI.Core.Mvvm/BaseViewModel.cs index 412d7b2..438aaae 100644 --- a/src/CSharp/EasyMicroservices.UI.Core.Mvvm/BaseViewModel.cs +++ b/src/CSharp/EasyMicroservices.UI.Core.Mvvm/BaseViewModel.cs @@ -9,12 +9,21 @@ namespace EasyMicroservices.UI.Core; /// /// /// -public abstract class BaseViewModel : IBusyViewModel, INotifyPropertyChanged +public abstract class BaseViewModel : IBusyViewModel, INotifyPropertyChanged, IDisposable { + /// + /// + /// + public BaseViewModel() + { + PropertyChanged += BaseViewModel_PropertyChanged; + } + /// /// /// public Action OnBusyChanged { get; set; } + Action _OnBindPropertyChanged; bool _IsBusy; /// @@ -159,4 +168,26 @@ public virtual Task DisplayError(string message) { return Task.CompletedTask; } + + /// + /// + /// + /// + public virtual void BindPropertyChanged(Action action) + { + _OnBindPropertyChanged = action; + } + + private void BaseViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e) + { + _OnBindPropertyChanged?.Invoke(); + } + + /// + /// + /// + public virtual void Dispose() + { + PropertyChanged -= BaseViewModel_PropertyChanged; + } } diff --git a/src/CSharp/EasyMicroservices.UI.Core.Mvvm/EasyMicroservices.UI.Core.Mvvm.csproj b/src/CSharp/EasyMicroservices.UI.Core.Mvvm/EasyMicroservices.UI.Core.Mvvm.csproj index 28a4e5b..467353d 100644 --- a/src/CSharp/EasyMicroservices.UI.Core.Mvvm/EasyMicroservices.UI.Core.Mvvm.csproj +++ b/src/CSharp/EasyMicroservices.UI.Core.Mvvm/EasyMicroservices.UI.Core.Mvvm.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.4 + 0.0.0.5 Model View View Model EasyMicroservices@gmail.com mvvm,mvpvm,modelview,modelviewviewmodel