Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>We have this issue in our application as well. The validation only fires when bindings update, so you have to update them by hand. We do this in the Window's <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.loaded(VS.95).aspx" rel="noreferrer">Loaded</a> event:</p> <pre><code>public void Window_Loaded(object sender, RoutedEventArgs e) { // we manually fire the bindings so we get the validation initially txtName.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtCode.GetBindingExpression(TextBox.TextProperty).UpdateSource(); } </code></pre> <p>This will make the error template (red outline) appear, and set the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.validation.haserror.aspx" rel="noreferrer">Validation.HasError</a> property, which we have triggering the OK button to disable:</p> <pre><code>&lt;Button x:Name="btnOK" Content="OK" IsDefault="True" Click="btnOK_Click"&gt; &lt;Button.Style&gt; &lt;Style TargetType="{x:Type Button}"&gt; &lt;Setter Property="IsEnabled" Value="false" /&gt; &lt;Style.Triggers&gt; &lt;!-- Require the controls to be valid in order to press OK --&gt; &lt;MultiDataTrigger&gt; &lt;MultiDataTrigger.Conditions&gt; &lt;Condition Binding="{Binding ElementName=txtName, Path=(Validation.HasError)}" Value="false" /&gt; &lt;Condition Binding="{Binding ElementName=txtCode, Path=(Validation.HasError)}" Value="false" /&gt; &lt;/MultiDataTrigger.Conditions&gt; &lt;Setter Property="IsEnabled" Value="true" /&gt; &lt;/MultiDataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/Button.Style&gt; &lt;/Button&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload