Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF error template not showing
    text
    copied!<p>I get no binding errors and this code works at another place. I haven't found out yet what I do now differently to the code where it works and it's not that much code.</p> <p>In <strong>UserControl.Resource:</strong></p> <pre><code>&lt;Style TargetType="TextBox"&gt; &lt;Setter Property="BorderBrush" Value="DarkBlue"/&gt; &lt;Setter Property="BorderThickness" Value="1"/&gt; &lt;Setter Property="Margin" Value="0,1,0,1"/&gt; &lt;Setter Property="Validation.ErrorTemplate"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;AdornedElementPlaceholder/&gt; &lt;Grid Margin="2,0,0,0"&gt; &lt;Ellipse Width="20" Height="20" Fill="Red"/&gt; &lt;TextBlock Foreground="White" Text="X" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center"/&gt; &lt;/Grid&gt; &lt;/StackPanel&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="Validation.HasError" Value="True"&gt; &lt;Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; </code></pre> <p><strong>Below in Xaml too:</strong></p> <pre><code>&lt;TextBlock Height="23" HorizontalAlignment="Left" Margin="22,90,0,0" Text="Keywords" VerticalAlignment="Top"/&gt; &lt;TextBox Height="23" HorizontalAlignment="Left" Margin="22,108,0,0" VerticalAlignment="Top" Width="244"&gt; &lt;Binding Path="Tags" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged"&gt; &lt;Binding.ValidationRules&gt; &lt;DataErrorValidationRule ValidatesOnTargetUpdated="False"/&gt; &lt;/Binding.ValidationRules&gt; &lt;/Binding&gt; &lt;/TextBox&gt; </code></pre> <p>The button SAVE in my ViewModel is only activated when the <code>Model.Tags</code> property is longer 10 chars input from the user. The button activation/disable works fine when I enter 10,11 and then back 8 chars. All the property changes are fired.</p> <p><strong>Model</strong>:</p> <pre><code>namespace TBM.Model { public class Document : EntityBase , IDataErrorInfo { public int Id { get; set; } public string DocumentName { get; set; } public string Tags { get; set; } public byte[] DocumentData { get; set; } public int PeriodId { get; set; } string IDataErrorInfo.Error { get { return null; } } string IDataErrorInfo.this[string propertyName] { get { return this.GetValidationError(propertyName); } } public bool IsValid { get { foreach (string property in ValidatedProperties) if (GetValidationError(property) != null) return false; return true; } } static readonly string[] ValidatedProperties = { "Tags", }; private string GetValidationError(string propertyName) { if (Array.IndexOf(ValidatedProperties, propertyName) &lt; 0) return null; string error = null; switch (propertyName) { case "Tags": error = this.IsTagsEmpty(Tags); break; default: Debug.Fail("Unexpected property being validated on Document: " + propertyName); break; } return error; } private string IsTagsEmpty(string value) { if (value != null &amp;&amp; value.Trim().Length &gt;= 10) return null; else return "The keywords must have at least 10 chars!"; } } } </code></pre> <p><strong>ViewModel</strong>:</p> <pre><code> public RelayCommand SaveDocumentCommand { get { return _saveDocumentCommand ?? (_saveDocumentCommand = new RelayCommand(() =&gt; SaveDocument(),() =&gt; CanSaveDocument())); } } private bool CanSaveDocument() { return _document.IsValid; } //... </code></pre> <p>What does not work is the ErrorTemplate with the red Ellipse is not showing at all?</p> <p><strong>UPDATE:</strong> Exactly the below code works in a TEST project. But in my productive project It does not find the Resource??? Why the heck this?</p> <pre><code>&lt;TextBlock Height="23" HorizontalAlignment="Left" Margin="22,89,0,0" Text="Keywords" VerticalAlignment="Top"/&gt; &lt;TextBox Style="{StaticResource bla}" Height="23" HorizontalAlignment="Left" Margin="22,109,0,0" VerticalAlignment="Top" Width="244"&gt; &lt;Binding Path="Tags" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged"&gt; &lt;Binding.ValidationRules&gt; &lt;DataErrorValidationRule ValidatesOnTargetUpdated="False" ValidationStep="UpdatedValue"/&gt; &lt;/Binding.ValidationRules&gt; &lt;/Binding&gt; &lt;/TextBox&gt; &lt;UserControl.Resources&gt; &lt;Style x:Name="bla" TargetType="TextBox"&gt; &lt;Setter Property="BorderBrush" Value="DarkBlue"/&gt; &lt;Setter Property="BorderThickness" Value="1"/&gt; &lt;Setter Property="Margin" Value="0,1,0,1"/&gt; &lt;Setter Property="Validation.ErrorTemplate"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;AdornedElementPlaceholder/&gt; &lt;Grid Margin="2,0,0,0"&gt; &lt;Ellipse Width="20" Height="20" Fill="Red"/&gt; &lt;TextBlock Foreground="White" Text="X" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center"/&gt; &lt;/Grid&gt; &lt;/StackPanel&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="Validation.HasError" Value="True"&gt; &lt;Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/UserControl.Resources&gt; </code></pre>
 

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