Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Need to put where the resource is coming from.</p> <pre><code>&lt;TextBox Style="{StaticResource textStyleTextBox}"/&gt; </code></pre> <p>Then define the style in a resource such as the user control resources:</p> <pre><code>&lt;UserControl.Resources&gt; &lt;Style TargetType="TextBox" x:Key="textStyleTextBox"&gt; &lt;Setter Property="Background" Value="Blue"/&gt; &lt;/Style&gt; &lt;/UserControl.Resources&gt; </code></pre> <p>However I dont believe you want to set the style of the adornedelement within the placeholder. It's just a placeholder for any control with that template. You should set the style of the adornedelement in the element itself like the example I provided above. If you want to style the control based upon it's validation then something like this:</p> <pre><code>&lt;Window.Resources&gt; &lt;ControlTemplate x:Key="validationTemplate"&gt; &lt;DockPanel&gt; &lt;TextBlock Foreground="Yellow" Width="55" FontSize="18"&gt;!&lt;/TextBlock&gt; &lt;AdornedElementPlaceholder/&gt; &lt;/DockPanel&gt; &lt;/ControlTemplate&gt; &lt;Style x:Key="textBoxInError" TargetType="{x:Type TextBox}"&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="Validation.HasError" Value="true"&gt; &lt;Setter Property="Background" Value="Red"/&gt; &lt;Setter Property="Foreground" Value="White"/&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/Window.Resources&gt; &lt;StackPanel x:Name="mainPanel"&gt; &lt;TextBlock&gt;Age:&lt;/TextBlock&gt; &lt;TextBox x:Name="txtAge" Validation.ErrorTemplate="{DynamicResource validationTemplate}" Style="{StaticResource textBoxInError}"&gt; &lt;Binding Path="Age" UpdateSourceTrigger="PropertyChanged" &gt; &lt;Binding.ValidationRules&gt; &lt;ExceptionValidationRule/&gt; &lt;/Binding.ValidationRules&gt; &lt;/Binding&gt; &lt;/TextBox&gt; &lt;/StackPanel&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