Another solution is to pull the IsEnabled value from the decorated element through the AdornedElement property of your AdornedElementPlaceholder . In the example below, I use IsEnabled="{Binding ElementName=customAdorner, Path=AdornedElement.IsEnabled}" . Then you can disable IsEnabled as usual.
<Style x:Key="TextBoxValidationStyle" TargetType="{x:Type TextBox}"> <Setter Property="Validation.ErrorTemplate"> <Setter.Value> <ControlTemplate> <DockPanel IsEnabled="{Binding ElementName=customAdorner, Path=AdornedElement.IsEnabled}"> <AdornedElementPlaceholder x:Name="customAdorner"> <Border x:Name="Border" BorderThickness="1"> <Border.Style> <Style TargetType="Border"> <Style.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter Property="BorderBrush" Value="Transparent" /> </Trigger> <Trigger Property="IsEnabled" Value="True"> <Setter Property="BorderBrush" Value="Red" /> </Trigger> </Style.Triggers> </Style> </Border.Style> </Border> </AdornedElementPlaceholder> </DockPanel> </ControlTemplate> </Setter.Value> </Setter> </Style>
The advantage is that this approach simplifies layout support if it is not an error, if you have other text blocks, etc. in ErrorTemplate .
source share