title: How to force another control to validate when a drop down's choice changes
body: <p>I have a WPF application with a dialog that is displayed to edit some settings.  The dialog contains, among other things, a <code>ComboBox</code> and a <code>TextBox</code>.  The <code>ComboBox</code> has two choices in it.  The contents of the <code>TextBox</code> need to be validated when one of those two choices is selected and should not be validated when it isn't.  Here's the XAML for the two controls:</p>
  
  <pre><code>&lt;ComboBox ItemsSource="{Binding Source={StaticResource LPRTypes}, Path=DisplayNames}"
            SelectedValue="{Binding Converter={StaticResource LPRTypes}, Mode=TwoWay, Path=LPRType}"
            Margin="5"
            Name="LPRTypePicker"
            TabIndex="1" /&gt;
  
  &lt;TextBox Margin="5,0,30,0"
           Name="DeviceIdBox"
           TabIndex="2"
           Text="{Binding Mode=TwoWay, NotifyOnSourceUpdated=True, Path=DeviceId, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
           TextChanged="DeviceIdBox_TextChanged" /&gt;
  </code></pre>
  
  <p>I'm also using the following template to display validation errors to the user:</p>
  
  <pre><code>        &lt;ControlTemplate x:Key="InputErrorTemplate"&gt;
              &lt;DockPanel LastChildFill="True"&gt;
                  &lt;Image DockPanel.Dock="Right"
                          Height="20"
                          Margin="-30,0,0,0"
                          Source="{StaticResource ErrorImage}"
                          ToolTip="{x:Static res:Car.Common_InvalidData}"
                          VerticalAlignment="Center"
                          Width="20" /&gt;
                  &lt;Border BorderBrush="Red"
                          BorderThickness="5"
                          Margin="5,0,30,0"&gt;
                      &lt;AdornedElementPlaceholder /&gt;
                  &lt;/Border&gt;
              &lt;/DockPanel&gt;
          &lt;/ControlTemplate&gt;
  
          &lt;Style TargetType="{x:Type TextBox}"&gt;
              &lt;Setter Property="Validation.ErrorTemplate" Value="{StaticResource InputErrorTemplate}" /&gt;
              &lt;Style.Triggers&gt;
                  &lt;Trigger Property="Validation.HasError" Value="True"&gt;
                      &lt;Setter Property="ToolTip"&gt;
                          &lt;Setter.Value&gt;
                              &lt;Binding Path="(Validation.Errors).CurrentItem.ErrorContent"
                                       RelativeSource="{x:Static RelativeSource.Self}" /&gt;
                          &lt;/Setter.Value&gt;
                      &lt;/Setter&gt;
                  &lt;/Trigger&gt;
              &lt;/Style.Triggers&gt;
          &lt;/Style&gt;
  </code></pre>
  
  <p>I have the following code in the <code>IDataError</code> implementation in the <code>ViewModel</code> object for the dialog:</p>
  
  <pre><code>public string this[ string columnName ] {
      get {
          switch ( columnName ) {
              // . . .
  
              case "DeviceId":
                  if ( LPRType == LPRTypes.AD3 )
                      return string.Empty;
  
                  if ( string.IsNullOrEmpty( DeviceId ) )
                      return Car.LPRCamera_MissingDeviceId;
                  break;
  
                  // . . .
  
              default:
                  // Verify that the property name matches a real,  public, instance property on this object. 
                  if ( TypeDescriptor.GetProperties( this )[ columnName ] == null ) {
                      return Car.ViewModelBase_InvalidProperty + columnName;
                  }
                  break;
          }
          return string.Empty;
      }
  }
  </code></pre>
  
  <p>The two possible values for <code>LPRType</code> are <code>Type1</code> and <code>Type2</code>.  When <code>LPRType</code> is <code>Type1</code>, the <code>DeviceId</code> column's value doesn't matter -- there should not be any error, even if it's null or empty.  But, if <code>LPRType</code> is <code>Type2</code>, then <code>DeviceId</code> must have a non-null or empty value.</p>
  
  <p>If you set the <code>LPRType</code> to <code>Type2</code>, then delete all content in the <code>TextBox</code>, an error is displayed on the <code>TextBox</code>, which is correct.  Now, if you change the value of <code>LPRType</code> back to <code>Type1</code>, the UI still displays the <code>TextBox</code> as an error.  This is wrong, since the value of the <code>DeviceId</code> doesn't matter when <code>LPRType</code> is <code>Type1</code>.</p>
  
  <p>How do I get the View Model to validate the <code>DeviceId</code> property when the <code>LPRType</code> changes?</p>