diff --git a/EZAppz.Core/Notifications/NotifyBase.cs b/EZAppz.Core/Notifications/NotifyBase.cs index 3e875b5..b5b92e1 100644 --- a/EZAppz.Core/Notifications/NotifyBase.cs +++ b/EZAppz.Core/Notifications/NotifyBase.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Linq; @@ -8,7 +9,7 @@ namespace EZAppz.Core { - public abstract class NotifyBase : DescribableObject, INotifyBase + public abstract class NotifyBase : DescribableObject, INotifyBase, INotifyDataErrorInfo { internal protected class PropertyRelation @@ -18,6 +19,45 @@ internal protected class PropertyRelation public HashSet RelatedChangingActions { get; } = new HashSet(); } private Dictionary PropertyRelations { get; } = new Dictionary(); + + + private Dictionary> Errors = new Dictionary>(); + public bool HasErrors => Errors.Any(x => x.Value.Count > 0); + + public IEnumerable GetErrors(string propertyName) + { + if (Errors.TryGetValue(propertyName, out var l)) + return l; + return null; + } + public void RaiseErrorChanged(string propertyName) + { + ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(propertyName)); + } + public void RaiseError(string error, [CallerMemberName] string prop = null) + { + if (Errors.ContainsKey(prop)) + { + Errors[prop].Add(error); + } + else + { + Errors[prop] = new List() { error }; + } + RaiseErrorChanged(prop); + } + public void ClearErrors([CallerMemberName]string prop = null) + { + if (Errors.ContainsKey(prop)) + { + Errors[prop].Clear(); + } + } + public void ClearAllErrors() + { + Errors.Clear(); + } + public NotifyBase(bool ImportFromReflection = false) : base(ImportFromReflection) { PropertyChanged += NotifyBase_PropertyChanged; @@ -137,11 +177,13 @@ public void RaisePropertyChanging([CallerMemberName] string prop = null) { PropertyChanging?.Invoke(this, new PropertyChangingEventArgs(prop)); } - + [field: NonSerialized] public event PropertyChangingEventHandler PropertyChanging; [field: NonSerialized] public event PropertyChangedEventHandler PropertyChanged; + [field: NonSerialized] + public event EventHandler ErrorsChanged; } }