Open kahko opened 3 years ago
How about using a Button to add a new item for DataGrid? Or set MoveFocus
DataGrid to add a new Item for DataGrid like below:
private void myGrid_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
int i = myGrid.Items.Count - 1;
if(i==1)
{
myGrid.SelectedIndex = 0;
DataGridRow row = (DataGridRow)myGrid.ItemContainerGenerator.ContainerFromIndex(1);
row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}
}
@daisyTian0517 Thanks for the reply, but I'm not looking for workarounds - just reporting what I think is a bug.
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:
<DataGrid Grid.Column="0" ItemsSource="{Binding Collection}" />
ViewModel:
Click the unfocusable button without finishing started new row:
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.