dotnet / dotnet/wpf

Datagrid loses its new row placeholder when binded collection is cleared from non-focusable button while user is editing new row.

Open
#4,032 2 comments 2 reactions 0 assignees View on GitHub
.NET Framework
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

* .NET Core Version: **.NET Core 3.1**
* Windows version: **Win 10 version 1909**
* Does the bug reproduce also in WPF for .NET Framework 4.8?: **Yes**
* Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc...)?: **No**

**Problem description:**
When user is editing a new row and clears the collection the datagrid is binded to, datagrid does not get new empty row placeholder. Since datagrid has no editable rows, user can not add new data to it. This only happens when collection.clear() command is binded to a unfocusable button.

**Actual behavior:**
Use attached repo or create new with:
View:






ViewModel:

public class MainVM
{
public ObservableCollection Collection { get; } = new ObservableCollection();

private ICommand _clearCommand;
public ICommand ClearCommand
{
get
{
if (_clearCommand is null)
_clearCommand = new RelayCommand(_ => Collection.Clear(), _ => Collection.Any());
return _clearCommand;
}
}
}

public class A
{
public string Name { get; set; }
public int Age { get; set; }
}

1. Start creating datagridrow:
![editing](https://user-images.githubusercontent.com/11559305/105182508-c74c6900-5b35-11eb-8470-dbfc610bf81a.png)
2. Click the unfocusable button without finishing started new row:
![result](https://user-images.githubusercontent.com/11559305/105182651-f5ca4400-5b35-11eb-948a-910553685a9e.png)

**Expected behavior:**
Datagrid does not lose its new row placeholder and user is able to add new rows.

**Minimal repro:**
https://github.com/kahko/WPFDatagridClearBug

Solution has both .NET Core and .NET Framework projects.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.