Browse Source
Merge pull request #9921 from almightyju/datagrid-fixes
Fix DataGridTemplateColumn reusing edit control when exiting edit mode
pull/9949/head
Max Katz
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
24 additions and
4 deletions
-
src/Avalonia.Controls.DataGrid/DataGrid.cs
-
src/Avalonia.Controls.DataGrid/DataGridColumn.cs
-
src/Avalonia.Controls.DataGrid/DataGridTemplateColumn.cs
|
|
|
@ -4152,6 +4152,7 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
if (exitEditingMode) |
|
|
|
{ |
|
|
|
CurrentColumn.EndCellEditInternal(); |
|
|
|
_editingColumnIndex = -1; |
|
|
|
editingCell.UpdatePseudoClasses(); |
|
|
|
|
|
|
|
|
|
|
|
@ -800,11 +800,22 @@ namespace Avalonia.Controls |
|
|
|
protected internal virtual void RefreshCellContent(Control element, string propertyName) |
|
|
|
{ } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// When overridden in a derived class, called when a cell in the column exits editing mode.
|
|
|
|
/// </summary>
|
|
|
|
protected virtual void EndCellEdit() |
|
|
|
{ } |
|
|
|
|
|
|
|
internal void CancelCellEditInternal(Control editingElement, object uneditedValue) |
|
|
|
{ |
|
|
|
CancelCellEdit(editingElement, uneditedValue); |
|
|
|
} |
|
|
|
|
|
|
|
internal void EndCellEditInternal() |
|
|
|
{ |
|
|
|
EndCellEdit(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Coerces a DataGridLength to a valid value. If any value components are double.NaN, this method
|
|
|
|
/// coerces them to a proper initial value. For star columns, the desired width is calculated based
|
|
|
|
|
|
|
|
@ -55,17 +55,25 @@ namespace Avalonia.Controls |
|
|
|
get => _cellEditingCellTemplate; |
|
|
|
set => SetAndRaise(CellEditingTemplateProperty, ref _cellEditingCellTemplate, value); |
|
|
|
} |
|
|
|
|
|
|
|
private static void OnCellTemplateChanged(AvaloniaPropertyChangedEventArgs e) |
|
|
|
|
|
|
|
private bool _forceGenerateCellFromTemplate; |
|
|
|
|
|
|
|
protected override void EndCellEdit() |
|
|
|
{ |
|
|
|
var oldValue = (IDataTemplate)e.OldValue; |
|
|
|
var value = (IDataTemplate)e.NewValue; |
|
|
|
//the next call to generate element should not resuse the current content as we need to exit edit mode
|
|
|
|
_forceGenerateCellFromTemplate = true; |
|
|
|
base.EndCellEdit(); |
|
|
|
} |
|
|
|
|
|
|
|
protected override Control GenerateElement(DataGridCell cell, object dataItem) |
|
|
|
{ |
|
|
|
if (CellTemplate != null) |
|
|
|
{ |
|
|
|
if (_forceGenerateCellFromTemplate) |
|
|
|
{ |
|
|
|
_forceGenerateCellFromTemplate = false; |
|
|
|
return CellTemplate.Build(dataItem); |
|
|
|
} |
|
|
|
return (CellTemplate is IRecyclingDataTemplate recyclingDataTemplate) |
|
|
|
? recyclingDataTemplate.Build(dataItem, cell.Content as Control) |
|
|
|
: CellTemplate.Build(dataItem); |
|
|
|
|