title: how do i apply Validation Attributes to WPF
body: <p>In my project i have this window to add new <code>Contact</code> object </p>
  
  <p>My Question is how i apply this Validation Attributes to WPF window like i do in Asp.net MVC .. like <code>[Required]</code> and some <code>[ReularExpression()]</code></p>
  
  <pre><code>&lt;Window x:Class="WPFClient.AddNewContact"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="AddNewContact" Height="401" Width="496" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:my="clr-namespace:WPFClient.PhoneBookServiceReference" Loaded="Window_Loaded"&gt;
      &lt;Window.Resources&gt;
      &lt;/Window.Resources&gt;
      &lt;Grid Height="355" Width="474"&gt;
          &lt;GroupBox Header="Add Contact" Margin="0,0,0,49"&gt;
              &lt;Grid HorizontalAlignment="Left" Margin="21,21,0,0" Name="grid1" VerticalAlignment="Top" Height="198" Width="365"&gt;
              &lt;Grid.ColumnDefinitions&gt;
                  &lt;ColumnDefinition Width="Auto" /&gt;
                  &lt;ColumnDefinition Width="194" /&gt;
                      &lt;ColumnDefinition Width="64*" /&gt;
                  &lt;/Grid.ColumnDefinitions&gt;
              &lt;Grid.RowDefinitions&gt;
                  &lt;RowDefinition Height="Auto" /&gt;
                  &lt;RowDefinition Height="Auto" /&gt;
                  &lt;RowDefinition Height="Auto" /&gt;
                  &lt;RowDefinition Height="Auto" /&gt;
                  &lt;RowDefinition Height="53" /&gt;
                      &lt;RowDefinition Height="17*" /&gt;
                  &lt;/Grid.RowDefinitions&gt;
  
                  &lt;Label Content="Name:" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" /&gt;
                  &lt;TextBox Grid.Column="1" Grid.Row="0" Height="23" HorizontalAlignment="Left" Margin="0,3,0,6" Name="nameTextBox" VerticalAlignment="Center" Width="120" /&gt;
  
                  &lt;Label Content="Email:" Grid.Column="0" Grid.Row="1" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" /&gt;
                  &lt;TextBox Grid.Column="1" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="0,3,0,6" Name="emailTextBox" VerticalAlignment="Center" Width="120" /&gt;
  
                  &lt;Label Content="Phone Number:" Grid.Column="0" Grid.Row="2" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" /&gt;
                  &lt;TextBox Grid.Column="1" Grid.Row="2" Height="23" HorizontalAlignment="Left" Margin="0,3,0,6" Name="phoneNumberTextBox" VerticalAlignment="Center" Width="120" /&gt;
  
                  &lt;Label Content="Mobil:" Grid.Column="0" Grid.Row="3" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" /&gt;
                  &lt;TextBox Grid.Column="1" Grid.Row="3" Height="23" HorizontalAlignment="Left" Margin="0,3,0,6" Name="mobilTextBox" VerticalAlignment="Center" Width="120" /&gt;
  
  
                  &lt;Label Content="Address:" Grid.Column="0" Grid.Row="4" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" /&gt;
                  &lt;TextBox  Grid.Row="4" Grid.Column="1" Height="39" HorizontalAlignment="Left" Margin="0,0,0,14" Name="addressTextBox" 
                               VerticalAlignment="Center" Width="194" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" AcceptsReturn="True"  /&gt;
              &lt;/Grid&gt;
          &lt;/GroupBox&gt;
               &lt;Button Content="Add" Height="23" HorizontalAlignment="Left" Margin="24,273,0,0" Name="btnAdd" VerticalAlignment="Top" Width="75" Click="btnAdd_Click" /&gt;
          &lt;Button Content="Cancel" Height="23" HorizontalAlignment="Left" Margin="123,273,0,0" Name="btnCancel" VerticalAlignment="Top" Width="75" Click="btnCancel_Click" /&gt;
  
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>And i have this ModelView class to map Contact Object</p>
  
  <pre><code> public class MContact
   {
        [Required(ErrorMessage = " Name is required.")]
        [StringLength(50, ErrorMessage = "No more than 50 characters")]
        [Display(Name = "Name")]
        public string Name { get; set; }
  
  
        [Required(ErrorMessage = "Email is required.")]
        [StringLength(50, ErrorMessage = "No more than 50 characters")]
        [RegularExpression(".+\\@.+\\..+", ErrorMessage = "Valid email required e.g. abc@xyz.com")]
        public string Email { get; set; }
  
  
        [Display(Name = "Phone Number")]
        [Required]
        [RegularExpression(@"^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$",
              ErrorMessage = "Entered phone format is not valid.")]
        public string PhoneNumber { get; set; }
  
        public string Address { get; set; }
        [RegularExpression(@"^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$",
      ErrorMessage = "Entered phone format is not valid.")]
        public string Mobil { get; set; }
  
   }
  </code></pre>