I've been using the following error adorner template for a long time now:
<ControlTemplate x:Key="ErrorAdornerTemplateStyle" TargetType="{x:Type Control}">
<Grid ClipToBounds="False" >
<Border BorderBrush="Red" BorderThickness="2" Margin="-1"
ToolTip="{Binding ElementName=adornedElement, Path=AdornedElement.(Validation.Errors).CurrentItem.ErrorContent }">
<AdornedElementPlaceholder Name="adornedElement" />
</Border>
<Polygon Points="15,15 15,0 0,0"
Fill="Red"
HorizontalAlignment="Right"
VerticalAlignment="Top"
ToolTip="{Binding ElementName=adornedElement, Path=AdornedElement.(Validation.Errors).CurrentItem.ErrorContent }"/>
</Grid>
</ControlTemplate>
... and it works at run-time just fine (as far as I can tell).
However, after a flurry of upgrades to VS and WPF and NET Standard 2 in the past month, I've noticed that the intellisense in my syles xaml file is giving me the following error for the CurrentItem
identifier:
The property 'CurrentItem' was not found in type 'ReadOnlyObservableCollection'.
Is this just a nuisance VS bug or is VS alerting me to some kind of change in the WPF subsystem that I need to adapt to?
The ReadOnlyObservableCollection
itself doesn't expose a CurrentItem
property. Instead, the CurrentItem
is a concept of the CollectionView
that is internally created when a collection of items is bound in WPF.
There is some special support to access the CurrentItem
of a collection by using /
in the binding path.
Change the binding path to Path=AdornedElement.(Validation.Errors)/ErrorContent
to utilize this support.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With