WPF DataGridRow.IsNewItem Remained True even after DataGridRow.Item its NOT CollectionView.NewItemPlaceholder

Viewed 827

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 Answers

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>
Related