WPF DataGridRow.IsNewItem即使在DataGridRow.Item不是NOT CollectionView.NewItemPlaceholder之后也保持为True [英] WPF DataGridRow.IsNewItem Remained True even after DataGridRow.Item its NOT CollectionView.NewItemPlaceholder
问题描述
跟踪DataGridRow.Item
和DataGridRow.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
.
Afterwards I looked at MSDN and saw that it was indeed affected by two factors:
获取或设置一个值,该值指示DataGridRow是新项目还是尚未提交的项目的占位符.
如何提交添加的项目?
推荐答案
您可以完全在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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!