问题
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:
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.
How do I committ added item?
回答1:
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>
来源:https://stackoverflow.com/questions/20862356/wpf-datagridrow-isnewitem-remained-true-even-after-datagridrow-item-its-not-coll