本文介绍了WPF DataGridRow.IsNewItem即使在DataGridRow.Item不是NOT CollectionView.NewItemPlaceholder之后也保持为True的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

跟踪DataGridRow.ItemDataGridRow.IsNewItem属性后,我发现:每个添加的项(当Source为ObservableCollection<MyClass>时添加到DataGrid),IsNewItem总是积极的,尽管Item尽管他不是NewItemPlaceholder.

After tracking the DataGridRow.Item and DataGridRow.IsNewItem properties, I discover that: each added item (to DataGrid when Source is ObservableCollection<MyClass>), IsNewItem Always positive, Although Item Although he is not a NewItemPlaceholder.

此后,我查看了 MSDN ,发现它确实受到两个因素的影响:

Afterwards I looked at MSDN and saw that it was indeed affected by two factors:

如何提交添加的项目?

推荐答案

您可以完全在XAML中与NewItemPlaceholder进行比较:

You can do the comparison against NewItemPlaceholder purely in XAML:

<DataTemplate.Triggers>
    <DataTrigger Binding="{Binding Item, RelativeSource={RelativeSource FindAncestor, AncestorType=DataGridRow}}"
                 Value="{x:Static CollectionView.NewItemPlaceholder}">
        <Setter TargetName="Text" Property="Visibility" Value="Hidden" />
    </DataTrigger>
</DataTemplate.Triggers>

这篇关于WPF DataGridRow.IsNewItem即使在DataGridRow.Item不是NOT CollectionView.NewItemPlaceholder之后也保持为True的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 15:45