gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 07:59:47 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com