title: MVVMLight - ModernWindow - Validation
body: <p>I have an issue with view validation using IDataErrorInfo in my model object.
  I have an application with several pages using ModernWindow control.</p>
  
  <p>At startup, the validation is working fine. But once I navigated one time on the view, when I come back to one of the view already visited the validation don't work any more but IDataErrorInfo valiation method is called, something miss me in the knowledge of the functioning of the framework.</p>
  
  <p>If someone has already encountered this problem, he is welcome</p>
  
  <p>Sample code for ViewModel :</p>
  
  <pre><code>public class MyViewModel : ViewModelBase 
  {
       public readonly IDataAccessService ServiceProxy;
       private User _myUser
       public User MyUser
       {
           get { return _myUser; }
           set
        {
            _myUser= value;
             RaisePropertyChanged("MyUser");
        }
    }
  
     public MyViewModel(IDataAccessService serviceProxy)
  {
      ServiceProxy = serviceProxy;
      MyUser = new User();
  
      ReadAllCommand = new RelayCommand(GetUsers);
      SaveCommand = new RelayCommand&lt;User&gt;(SaveUser);
      SearchCommand = new RelayCommand(SearchUser);
      SendProctorCommand = new RelayCommand&lt;User&gt;(SendUser);
      DeleteProctorCommand = new RelayCommand&lt;User&gt;(DeleteUser);
      ReceiveUser();
  
  }
  private void ReceiveUser()
  {
      if (Proctor != null)
      {
          Messenger.Default.Register&lt;MessageCommunicator&gt;(this, (user) =&gt; {
              this.MyUser= user.User;
          });
      }
  }
  
  private  void SendUser(User user)
  {
      if (user!= null)
      {
  
          Messenger.Default.Send&lt;MessageCommunicator&gt;(new MessageCommunicator()
          {
              User = user
          });                             
      }
  }
  </code></pre>
  
  <p>The entity code (only those parts which concern the problem) :</p>
  
  <pre><code>public partial class User : ObservableObject, IDataErrorInfo
  {
  
  
  [NotMapped]
  public string Error
  {
      get
      {
          return this[null];
      }
  }
  
  public string this[string columnName]
  {
      get
      {
          string result = null;
          if (columnName == "Lastname")
          {
              if (string.IsNullOrEmpty(Lastname))
                  result = "Please enter a lastname";
              else
              if (Lastname.Length &lt; 5)
                  result = "The lastname must have 5 characters at least";
          }
  
          ...
          return result;
      }
    }
  </code></pre>
  
  <p>A sample for one field in the XAML :</p>
  
  <pre><code> &lt;TextBox Grid.Column="1" Grid.Row="0"  x:Name="LastnameTextBox" TextWrapping="Wrap" Text="{Binding UpdateSourceTrigger=PropertyChanged, Path= MyUser.Lastname  ,Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=true}" LostFocus="LastnameTextBox_LostFocus" /&gt;
  </code></pre>
  
  <p>TextBoxStyle.Xaml :</p>
  
  <pre><code> &lt;Style TargetType="TextBox" x:Key="StandardTextBox"&gt;
      &lt;Setter Property="Validation.ErrorTemplate"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate&gt;
                  &lt;DockPanel LastChildFill="true"&gt;
                      &lt;Border Background="Red" DockPanel.Dock="right" Margin="5,0,0,0" Width="20" Height="20" CornerRadius="10"
                                  ToolTip="{Binding ElementName=customAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"&gt;
                          &lt;TextBlock Text="!" VerticalAlignment="center" HorizontalAlignment="center" FontWeight="Bold" Foreground="white"&gt;
                          &lt;/TextBlock&gt;
                      &lt;/Border&gt;
                      &lt;AdornedElementPlaceholder Name="customAdorner" VerticalAlignment="Center" &gt;
                          &lt;Border BorderBrush="red" BorderThickness="1" /&gt;
                      &lt;/AdornedElementPlaceholder&gt;
                  &lt;/DockPanel&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  
      &lt;Setter Property="VerticalAlignment" Value="Center"&gt;&lt;/Setter&gt;
  
  &lt;/Style&gt;
  </code></pre>