Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>on the code behind add a partial class to each table.</p> <p>The property [HasNoError] is return true if there are no errors </p> <p>The property [Error] is return the errors as string </p> <pre><code>if(tablename.HasNoError) { // do your logic } else { // display tablename.Error } </code></pre> <p>In the xaml side use the binding</p> <pre><code>&lt;DataGridTextColumn Binding="{Binding Path=ActualFieldName1, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged }" Header=" ActualFieldName1" /&gt; </code></pre> <p>and this is the class sample using IDataErrorInfo-</p> <pre><code>public partial class tablename : IDataErrorInfo { private Dictionary&lt;string, string&gt; errorCollection = new Dictionary&lt;string, string&gt;(); public bool HasNoError { get { return string.IsNullOrWhiteSpace(Error); } } public string Error { get { if (errorCollection.Count == 0) return null; StringBuilder errorList = new StringBuilder(); var errorMessages = errorCollection.Values.GetEnumerator(); while (errorMessages.MoveNext()) errorList.AppendLine(errorMessages.Current); return errorList.ToString(); } } public string this[string fieldName] { get { string result = null; switch (fieldName) { case "ActualFieldName1": if (string.IsNullOrWhiteSpace(this.ActualFieldName1)) { result = "ActualFieldName1 is required."; }; if (Other_Condition) { result = "Other Result"; }; break; case "ActualFieldName2": if (string.IsNullOrWhiteSpace(this.ActualFieldName2)) { result = "ActualFieldName2 is required."; }; if (Other_Condition) { result = "Other Result"; }; break; // and so } if (result != null &amp;&amp; !errorCollection.ContainsKey(fieldName)) errorCollection.Add(fieldName, result); if (result == null &amp;&amp; errorCollection.ContainsKey(fieldName)) errorCollection.Remove(fieldName); return result; } } } </code></pre> <p>To make it nice add some style to target the error template see the example</p> <pre><code>&lt;Style TargetType="{x:Type TextBox}"&gt; &lt;Setter Property="Validation.ErrorTemplate"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate&gt; &lt;Border BorderBrush="Red" BorderThickness="1"&gt; &lt;Grid&gt; &lt;AdornedElementPlaceholder x:Name="MyAdorner"/&gt; &lt;Image Width="{Binding AdornedElement.ActualHeight, ElementName=MyAdorner}" Margin="0" ToolTip="{Binding AdornedElement.(Validation.Errors)[0].ErrorContent, ElementName=MyAdorner}" HorizontalAlignment="Right" VerticalAlignment="Center" Source="/Path/Exclamation.png" /&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre>
    singulars
    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.
 

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