Sourcecollection count - 0 newitemholderholder is not displayed

After deleting all the items in the linked collection, datagrid.items.count is 1, and the only item in the item collection is newitemplaceholder, but the newitemplaceholder is not displayed in the datagrid. This can only happen if the last item is a new user and you are trying to edit it, but instead of clicking on input, you click on the button that triggers the delete event.

Since the selected item is no longer a new user due to an editing event, this item is considered a new item in the source set.

Before calling delete, the item has an item.count of 2.

Any help on how to get a newitemplaceholder to appear in this weird situation?

+3
source share
1 answer

I faced the same problem, moreover, this happened not only when the number of source counts is 0, but for any last line in the editing state - after deleting from the editing state, the new record line at the bottom of the grid disappears. I did not find anything better than this - a rather rude and not very quick solution, but at least it works for me and, of course, better than nothing.

Given the DataGrid named grItems, a link to the _vm private view model, which has the Items property used to bind the data grid, the sample code might look like this:

 <DataGrid Name="grItems"
        ItemsSource="{Binding Path=Items}" 
        UnloadingRow="DataGridUnloadingRow">

and the code behind:

    private void DataGridUnloadingRow(object sender, DataGridRowEventArgs e)
    {
        grItems.UnloadingRow -= DataGridUnloadingRow;
        grItems.ItemsSource = null;
        grItems.ItemsSource = _vm.Items;
        grItems.UnloadingRow += DataGridUnloadingRow;
    } 

UPDATE

, , - WPF " ...". , , , Items. - , - . , - "" , , .

0

Source: https://habr.com/ru/post/1762954/


All Articles