为什么现在AdornedElement.(Validation.Errors).CurrentItem.ErrorContent(VS2017 15.4)会导致智能感知错误? [英] Why does AdornedElement.(Validation.Errors).CurrentItem.ErrorContent now (VS2017 15.4) cause intellisense errors?

查看:281
本文介绍了为什么现在AdornedElement.(Validation.Errors).CurrentItem.ErrorContent(VS2017 15.4)会导致智能感知错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很长一段时间以来,我一直在使用以下错误装饰模板:

<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>

...,它在运行时就可以正常工作(据我所知).

但是,在过去一个月对VS,WPF和NET Standard 2进行了一系列升级之后,我注意到syles xaml文件中的intellisense给我CurrentItem标识符以下错误:

在类型'ReadOnlyObservableCollection'中找不到属性'CurrentItem'.

这只是一个令人讨厌的VS错误还是VS提醒我一些我需要适应的WPF子系统更改?

解决方案

ReadOnlyObservableCollection本身不公开CurrentItem属性.相反,CurrentItemCollectionView的概念,是在WPF中绑定项目集合时在内部创建的.

有一些访问CurrentItem的特殊支持的集合,方法是在绑定路径中使用/.

将绑定路径更改为Path=AdornedElement.(Validation.Errors)/ErrorContent以利用此支持.

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.

这篇关于为什么现在AdornedElement.(Validation.Errors).CurrentItem.ErrorContent(VS2017 15.4)会导致智能感知错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆