跟踪DataGridRow.Item
之后和 DataGridRow.IsNewItem
属性,我发现:每个添加的项目(当 Source 为 ObservableCollection<MyClass>
时添加到 DataGrid),
IsNewItem
总是积极的,虽然Item
虽然他不是NewItemPlaceholder
.
后来我看了MSDN并看到它确实受到两个因素的影响:
Gets or sets a value that indicates whether the DataGridRow is a placeholder for a new item or for an item that has not been committed.
我如何提交添加的项目?
最佳答案
您可以完全在 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>
关于WPF DataGridRow.IsNewItem 即使在 DataGridRow.Item 不是 CollectionView.NewItemPlaceholder 之后仍保持为真,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20862356/