Browse Source

Implement DataContext update notifications on the DataGrid

This fixes #5661 by allowing the DataGrid to notify its cells that their DataContext is about to be changed.
pull/8668/head
aldelaro5 4 years ago
parent
commit
ed582a9fde
  1. 32
      src/Avalonia.Controls.DataGrid/DataGrid.cs

32
src/Avalonia.Controls.DataGrid/DataGrid.cs

@ -2167,6 +2167,38 @@ namespace Avalonia.Controls
return desiredSize;
}
/// <inheritdoc/>
protected override void OnDataContextBeginUpdate()
{
base.OnDataContextBeginUpdate();
foreach (DataGridRow row in GetAllRows())
{
foreach (DataGridCell cell in row.Cells)
{
if (cell.Content is StyledElement)
{
DataContextProperty.Notifying?.Invoke((IAvaloniaObject)cell.Content, true);
}
}
}
}
/// <inheritdoc/>
protected override void OnDataContextEndUpdate()
{
base.OnDataContextEndUpdate();
foreach (DataGridRow row in GetAllRows())
{
foreach (DataGridCell cell in row.Cells)
{
if (cell.Content is StyledElement)
{
DataContextProperty.Notifying?.Invoke((IAvaloniaObject)cell.Content, false);
}
}
}
}
/// <summary>
/// Raises the BeginningEdit event.

Loading…
Cancel
Save