WPF DataGridRow.IsNewItem即使在DataGridRow.Item之后仍然为True,而不是CollectionView.NewItemPlaceholder

WPF DataGridRow.IsNewItem即使在DataGridRow.Item之后仍然为True,而不是CollectionView.NewItemPlaceholder,wpf,datagrid,observablecollection,Wpf,Datagrid,Observablecollection,跟踪DataGridRow.Item和DataGridRow.IsNewItem属性后,我发现:每个添加的项(当源代码为observeCollection时添加到DataGrid中), IsNewItem始终为正值,尽管他不是newitem占位符 后来我看了看,确实受到两个因素的影响: 获取或设置一个值,该值指示DataGridRow是新项的占位符还是尚未提交的项的占位符 如何提交添加的项目?您可以纯粹在XAML中与NewItemPlaceholder进行比较: <DataTemplate

跟踪
DataGridRow.Item
DataGridRow.IsNewItem
属性后,我发现:每个添加的项(当源代码为
observeCollection
时添加到DataGrid中),
IsNewItem
始终为正值,尽管他不是
newitem占位符

后来我看了看,确实受到两个因素的影响:

获取或设置一个值,该值指示DataGridRow是新项的占位符还是尚未提交的项的占位符


如何提交添加的项目?

您可以纯粹在XAML中与
NewItemPlaceholder
进行比较:

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


是否未检查
项是否为NewItemPlaceHolder
足够?足够,但不是来自XAML。。。