Hi,
Just learning WPF and I wondered if there's an easy way to amend a controls control template with c# code?
To explain - I'm using two 'types' of validation - one to ensure the data conforms to the requirements of an underlying table, and another to ensure the data conforms to another set of rules. The validations are applied dynamically as required, but I can't figure out how to change the error template.
The first validation uses this;
<Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBoxBase}">
<Setter Property="Margin" Value="2" />
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="MinWidth" Value="120"/>
<Setter Property="MinHeight" Value="20"/>
<Setter Property="AllowDrop" Value="true"/>
<!--ERROR TEMPLATE-->
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<DockPanel LastChildFill="True">
<Border BorderBrush="Purple" BorderThickness="2" CornerRadius="4,4,4,4" SnapsToDevicePixels="True" >
<AdornedElementPlaceholder />
</Border>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
Can someone tell me how to create the equivalent in C# code, and then I can amend as required and reapply it for the second validation.
Thanks