WPF DataGridRow.IsNewItem 即使在 DataGridRow.Item 不是 CollectionView.NewItemPlaceholder 之后仍保持为真

标签 wpf datagrid observablecollection

跟踪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/

相关文章:

WPF 工具包数据网格 : how to get ColumnHeader width to be the same as GridColumn width

wpf - DataGridComboBoxColumn 单元格不显示所选项目文本?

java - 如何更高效地更新TriangleMesh的点?

.net - VS : Events cannot be set on the object passed to the event binding service 中的设计器问题

wpf - 如何向用户控件添加更多资源

wpf - DataGrid 未绑定(bind)(XAML + ViewModel + ObservableCollection)

c# - 如何从列表控件向 ViewModel ObservableCollection 属性添加项目? WPF MVVM

绑定(bind)到在单独线程上更新的 ObservableCollection 的 WPF DataGrid 无法维护排序

c# - 将一个类中的值绑定(bind)到另一类中的另一个值

c# - WPF跨线程对象访问