diff --git a/src/Smaragd/ViewModels/DialogModel.cs b/src/Smaragd/ViewModels/DialogModel.cs
index 489627a..6ec8c3f 100644
--- a/src/Smaragd/ViewModels/DialogModel.cs
+++ b/src/Smaragd/ViewModels/DialogModel.cs
@@ -2,7 +2,7 @@
{
///
public abstract class DialogModel
- : ValidatingViewModel, IDialogModel
+ : ViewModel, IDialogModel
{
private string _title;
diff --git a/src/Smaragd/ViewModels/IBindable.cs b/src/Smaragd/ViewModels/IBindable.cs
index f2e4c4e..adaab8d 100644
--- a/src/Smaragd/ViewModels/IBindable.cs
+++ b/src/Smaragd/ViewModels/IBindable.cs
@@ -2,6 +2,7 @@
namespace NKristek.Smaragd.ViewModels
{
+ ///
///
/// Notifies clients that a property value is changing or has changed.
///
diff --git a/src/Smaragd/ViewModels/IValidatingBindable.cs b/src/Smaragd/ViewModels/IValidatingBindable.cs
new file mode 100644
index 0000000..ba43508
--- /dev/null
+++ b/src/Smaragd/ViewModels/IValidatingBindable.cs
@@ -0,0 +1,13 @@
+using System.ComponentModel;
+
+namespace NKristek.Smaragd.ViewModels
+{
+ ///
+ ///
+ /// Notifies clients that errors of a property have changed.
+ ///
+ public interface IValidatingBindable
+ : IBindable, INotifyDataErrorInfo
+ {
+ }
+}
diff --git a/src/Smaragd/ViewModels/IValidatingViewModel.cs b/src/Smaragd/ViewModels/IValidatingViewModel.cs
deleted file mode 100644
index 4a5caff..0000000
--- a/src/Smaragd/ViewModels/IValidatingViewModel.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using System.Collections;
-using System.ComponentModel;
-
-namespace NKristek.Smaragd.ViewModels
-{
- ///
- ///
- /// Defines a which performs validation.
- ///
- public interface IValidatingViewModel
- : IViewModel, INotifyDataErrorInfo
- {
- ///
- /// If data is valid.
- ///
- bool IsValid { get; }
-
- ///
- /// Set validation errors of a property.
- ///
- /// The errors of the property.
- /// The name of the property.
- void SetErrors(IEnumerable errors, string propertyName = null);
- }
-}
\ No newline at end of file
diff --git a/src/Smaragd/ViewModels/IViewModel.cs b/src/Smaragd/ViewModels/IViewModel.cs
index a189f10..238b105 100644
--- a/src/Smaragd/ViewModels/IViewModel.cs
+++ b/src/Smaragd/ViewModels/IViewModel.cs
@@ -5,7 +5,7 @@
/// Defines properties which are useful for a viewmodel implementation.
///
public interface IViewModel
- : IBindable
+ : IValidatingBindable
{
///
/// Indicates if a property changed and the change is not persisted.
@@ -26,5 +26,10 @@ public interface IViewModel
/// Indicates if this instance is currently being updated.
///
bool IsUpdating { get; set; }
+
+ ///
+ /// If data is valid.
+ ///
+ bool IsValid { get; }
}
}
\ No newline at end of file
diff --git a/src/Smaragd/ViewModels/ValidatingViewModel.cs b/src/Smaragd/ViewModels/ValidatingBindable.cs
similarity index 79%
rename from src/Smaragd/ViewModels/ValidatingViewModel.cs
rename to src/Smaragd/ViewModels/ValidatingBindable.cs
index 9ff87b9..16dd91a 100644
--- a/src/Smaragd/ViewModels/ValidatingViewModel.cs
+++ b/src/Smaragd/ViewModels/ValidatingBindable.cs
@@ -4,26 +4,33 @@
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
-using NKristek.Smaragd.Attributes;
namespace NKristek.Smaragd.ViewModels
{
- ///
- public abstract class ValidatingViewModel
- : ViewModel, IValidatingViewModel
+ ///
+ public abstract class ValidatingBindable
+ : Bindable, IValidatingBindable
{
private readonly Dictionary> _errors = new Dictionary>();
- #region IValidatingViewModel
-
///
- [IsDirtyIgnored]
- [PropertySource(nameof(HasErrors))]
- public virtual bool IsValid => !HasErrors;
+ public virtual bool HasErrors => _errors.Count > 0;
///
+ public virtual IEnumerable GetErrors(string propertyName)
+ {
+ if (String.IsNullOrEmpty(propertyName))
+ return _errors.SelectMany(kvp => kvp.Value);
+ return _errors.TryGetValue(propertyName, out var errors) ? errors : Enumerable.Empty