This is a bit of a WPF whodunnit!
Update1:
Getting there! It seems that error templates are shown in the adorner layer. When I call var myAdornerLayer = AdornerLayer.GetAdornerLayer(this.txtCaseNumber);
myAdornerLayer is null. (After the control is loaded so it's not that). So it seems to be something do with adorners, rather than validation / templating per se.
Wierdly, the adorner layer seems to exist for another control I checked on another window. So it's not globally missing at least...
The Problem
Basically, I am using IDataErrorInfo on my view model to provide feedback on data entry errors. I can see this being called and working as expected, but the validation error template for the bound control is never displayed by WPF!
I have tried both using the built-in default textbox red border error template, a style error template, and a hard coded template. None of these are displayed in a data error situation.
Heres my xaml binding code:
<TextBox x:Name="txtCaseNumber"
Text="{Binding Path=CaseNumber, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"/>
Wierdly, the error gets into the Validation.Errors collection. The follow code results in my IDataErrorInfo error message getting displayed next to the bound control. This leads me to think the problem is on the xaml side, rather the viewmodel side.
<ContentPresenter
Content="{Binding ElementName=txtCaseNumber, Path=(Validation.Errors).CurrentItem}" />
Additionally,
System.Windows.Controls.Validation.GetHasError(txtCaseNumber)
returns true.
I am hosting WPF in winforms if that makes a difference. I can't find any references in my code or styles to Validation or ErrorTemplate so I'm pretty sure this isn't a styling own goal.
Any ideas WPF buffs?!