title: How to catch DataAnnotations Validation in MVVM
body: <p>How do i catch the validation from the DataAnnotations ?
  i research here but i didn't understand how it works</p>
  
  <p>so i hoppe some of you can enlighten my</p>
  
  <h1>here my current test code:</h1>
  
  <h2>Model</h2>
  
  <pre><code>public class Person // Represents person data.
  {
      /// &lt;summary&gt;
      /// Gets or sets the person's first name.
      /// &lt;/summary&gt;
      /// &lt;remarks&gt;
      /// Empty string or null are not allowed.
      /// Allow minimum of 2 and up to 40 uppercase and lowercase.
      /// &lt;/remarks&gt;
      [Required]
      [RegularExpression(@"^[a-zA-Z''-'\s]{2,40}$")]        
      public string FirstName{ get; set;}
  
      /// &lt;summary&gt;
      /// Gets or sets the person's last name.
      /// &lt;/summary&gt;
      /// &lt;remarks&gt;
      /// Empty string or null are not allowed.
      /// &lt;/remarks&gt;
      [Required]
      public string LastName { get; set;}
  
      public int Age{ get; set;}
  }
  </code></pre>
  
  <h2>View</h2>
  
  <pre><code>&lt;Window x:Class="DataAnnotationstest.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:local="clr-namespace:DataAnnotationstest"
          Title="MainWindow" Height="350" Width="525"&gt;
      &lt;Window.DataContext&gt;
          &lt;local:Person FirstName="Tomer" LastName="Shamam" /&gt;
      &lt;/Window.DataContext&gt;
      &lt;Grid&gt;
          &lt;StackPanel Margin="4,4,51,4"&gt;
              &lt;TextBox Text="{Binding FirstName, ValidatesOnDataErrors=True}" /&gt;
              &lt;TextBox Text="{Binding LastName, ValidatesOnDataErrors=True}" /&gt;
              &lt;TextBox Text="{Binding Age, ValidatesOnDataErrors=True}" /&gt;
          &lt;/StackPanel&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>do i need to implement something else to Person?
  i found <a href="https://stackoverflow.com/questions/7027613/how-to-retrieve-data-annotations-from-code-programmatically">here</a> the following code but like i said before i didn't understand how it's worke -.-</p>
  
  <pre><code>public static T GetAttributeFrom&lt;T&gt;(this object instance, string propertyName) where T : Attribute
  {
      var attrType = typeof(T);
      var property = instance.GetType().GetProperty(propertyName);
      return (T)property .GetCustomAttributes(attrType, false).First();
  }
  </code></pre>