Unplanned
Last Updated: 11 Oct 2024 07:05 by Martin Ivanov
Martin Ivanov
Created on: 11 Oct 2024 07:05
Category: GridView
Type: Bug Report
1
GridView: GridViewFooterRow height is not resized when the content of the column footers change

The height of the column footer is not updated properly to autofit the footer's content. Actually, this works when the footer content becomes bigger than the current (or the default) value, but if you change the content with a smaller one, the bigger height remains. In other words, the footer height autofits when the content becomes bigger but it doesn't decrease when the content becomes smaller after that.

To work this around, you can subscribe to the CellLoaded event and use reflection to update one of the internal properties of the panel that draws the footer cells.
private void gridView_CellLoaded(object sender, CellEventArgs e)
{
    if (e.Cell is GridViewFooterCell)
    {
        var row = e.Cell.ParentRow;
        Dispatcher.BeginInvoke(new Action(() =>
        {
            var aggregatesList = row.ChildrenOfType<AggregateResultsList>(); // the exact type of children that should be used to get the new height may vary based on your column Footer contents
            if (aggregatesList.Count() > 0)
            {
                var height = aggregatesList.Max(x => x.ActualHeight);

                var cellsPanel = e.Cell.ParentOfType<GridViewCellsPanel>();
                PropertyInfo minRowHeightProp = cellsPanel.GetType().GetProperty("MinRowHeight", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
                object minRowHeightPair = minRowHeightProp.GetValue(cellsPanel);
                PropertyInfo heightProp = minRowHeightPair.GetType().GetProperty("Second");
                heightProp.SetValue(minRowHeightPair, height);
            }
        }));
    }
}

 

0 comments