Note that there are some explanatory texts on larger screens.

plurals
  1. POValidation.ErrorTemplate Style Issue
    text
    copied!<p>I am trying to apply a style to a text box when the content is not valid.</p> <p>The following style works:</p> <pre><code> &lt;Style x:Key="textBoxNormalStyle" TargetType="{x:Type TextBox}"&gt; &lt;Setter Property="FontFamily" Value="Arial"/&gt; &lt;Setter Property="FontSize" Value="16"/&gt; &lt;Setter Property="ForceCursor" Value="False"/&gt; &lt;Setter Property="Foreground" Value="{StaticResource TextColor}"/&gt; &lt;Setter Property="FontWeight" Value="Bold"/&gt; &lt;Setter Property="HorizontalContentAlignment" Value="Left"/&gt; &lt;Setter Property="VerticalContentAlignment" Value="Center"/&gt; &lt;Setter Property="Padding" Value="3,0,3,0"/&gt; &lt;Setter Property="Margin" Value="2"/&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type TextBox}"&gt; &lt;Border Background="{StaticResource TextBackColor}" BorderBrush="{StaticResource BorderColor}" x:Name="Bd" CornerRadius="4" BorderThickness="2"&gt; &lt;ScrollViewer Margin="0" x:Name="PART_ContentHost"/&gt; &lt;/Border&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Setter Property="Validation.ErrorTemplate"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate&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="FontFamily" Value="Arial"/&gt; &lt;Setter Property="FontSize" Value="16"/&gt; &lt;Setter Property="ForceCursor" Value="False"/&gt; &lt;Setter Property="Foreground" Value="{StaticResource TextColor}"/&gt; &lt;Setter Property="FontWeight" Value="Bold"/&gt; &lt;Setter Property="HorizontalContentAlignment" Value="Left"/&gt; &lt;Setter Property="VerticalContentAlignment" Value="Center"/&gt; &lt;Setter Property="Padding" Value="3,0,3,0"/&gt; &lt;Setter Property="Margin" Value="2"/&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type TextBox}"&gt; &lt;Grid Name="test"&gt; &lt;Border Background="{StaticResource TextBackColor}" BorderBrush="#d99" x:Name="Bd" CornerRadius="4" BorderThickness="2"&gt; &lt;ScrollViewer Margin="0" x:Name="PART_ContentHost"/&gt; &lt;/Border&gt; &lt;Image Name="ErrorImage" Width="24" Height="24" Margin="0,0,4,0" Source="/Images/error.png" HorizontalAlignment="Right"&gt; &lt;/Image&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; </code></pre> <p></p> <p>However I want to get rid of the trigger above and move the control template within the trigger to the Validation.ErrorTemplate section. But when I do this the control for the error template does not display correctly (the size of the error template defaults to the size of the image contained within it, left aligned, and blocks the text the user might have typed in the textbox).</p> <p>Is there a cleaner way for the xaml above?</p>
 

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