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

不打扰是莪最后的温柔 提交于 2020-01-15 05:32:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!