Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does AdornedElement.(Validation.Errors).CurrentItem.ErrorContent now (VS2017 15.4) cause intellisense errors?

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?

like image 718
BCA Avatar asked Nov 08 '17 17:11

BCA


1 Answers

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.

like image 83
grek40 Avatar answered Oct 18 '22 04:10

grek40