title: Caliburn.Micro implementing INotifyDataErrorInfo
body: <p>I'm trying to find an elegant solution to implement <code>INotifiyDataErrorInfo</code> with Caliburn.Micro MVVM framework.</p>
  
  <p>I want to limit the amount of code that will be repeated in each VM that needs to implement the validation. 
  I started by writing a class that inherits <code>Screen</code> and implements <code>INotifiyDataErrorInfo</code>. It works correctly and all is fine, until I need validation on a VM that is not a <code>Screen</code>, but a <code>Conductor</code>.</p>
  
  <p>Of course, I could make a class that inherits <code>Conductor</code> and implements <code>INotifyDataErrorInfo</code> but that's quite annoying as I would have to basically make my own version of all "base" classes of Caliburn.Micro.</p>
  
  <p>One solution I had was to keep the <code>Screen</code> base class and create a <code>IValidator</code> interface that I would inject into my VM, something like this:</p>
  
  <pre><code>public interface IValidator&lt;T&gt; where T : INotifyDataErrorInfo
  {
      void Validates(T instance);
  
      IEnumerable GetErrors(string propertyName);
      bool HasErrors { get; }
  
      void Validate();
      void ValidateProperty&lt;TValue&gt;(TValue value, string propertyName = null);
      void ValidateProperty&lt;TValue, TProperty&gt;(TValue value, Expression&lt;Func&lt;TProperty&gt;&gt; property);
  }
  </code></pre>
  
  <p>It will then used in the VM in this way.</p>
  
  <pre><code>public class CreateCarViewModel : Conductor&lt;CreateCarViewModel&gt;.Collection.OneActive, INotifyDataErrorInfo
  {
     private readonly IValidator&lt;CreateCarViewModel&gt; validator;
  
     public CreateExperimentViewModel(IValidator&lt;CreateCarViewModel&gt; validator)
     {
         this.DisplayName = "Select a car";
  
         this.validator = validator;
         this.validator.Validates(this);
     }
  
     [Required]
     public string CarName
     {
         get
         {
             return this.carName;
         }
         set
         {
             if (this.carName != value)
             {
                 this.carName = value;
  
                 this.validator.ValidateProperty(value, () =&gt; this.CarName);
                 this.NotifyOfPropertyChange(() =&gt; CarName);
             }
         }
     }
  
     public event EventHandler&lt;DataErrorsChangedEventArgs&gt; ErrorsChanged;
  
     public System.Collections.IEnumerable GetErrors(string propertyName)
     {
         return this.validator.GetErrors(propertyName);
     }
  
     public bool HasErrors
     {
         get { return this.validator.HasErrors; }
     }
  
     ...
  
  }
  </code></pre>
  
  <p>This works pretty nicely, as it is very simple to implement the <code>INotifyDataErrorInfo</code> in the VMs, but the issue I have is triggering the <code>ErrorChanged</code> event. It must be triggered by the implementation of the <code>IValidator</code> as he is the one who knows when the errors have changed, and of course he cannot trigger directly.</p>
  
  <p>One idea I have was to have an event in the <code>IValidator</code> and subscribe to it in the VM so that it can trigger its own event, but I find that it makes a lot of code for nothing.</p>
  
  <p>Does anyone have a better idea?</p>
  
  <p>Thanks</p>