AvaloniaUI / Avalonia.Controls.TreeDataGrid

A combined TreeView/DataGrid for Avalonia.
MIT License
234 stars 49 forks source link

Columns with Star width are set to the minimum available width #209

Closed berruezo closed 10 months ago

berruezo commented 10 months ago

When setting a GridLength of GridUnitType.Star in a TemplateColumn, the actual width is not calculated correctly, and the column gets the minimum width possible:

image

Digging into the code I saw that this method is always receiving 0 as the availableWidth, whereas in the previous version it received the actual available width for the column image

grokys commented 10 months ago

I've tried to repro this but been unable to. I know we spoke in chat and you were unable to get a simple repro, but could you maybe describe how your columns are set up? Might give more of a clue.

berruezo commented 10 months ago

Yes, the TemplateColumns in the table are created using this method:

        static IColumn<T> BuildTemplateColumn(
            string columnName,
            int columnWidth,
            Func<string, T, PlasticTableCell> cellFunc,
            IComparer<T> comparer)
        {
            return new TemplateColumn<T>(
                columnName,
                new FuncDataTemplate<T>((T node, INameScope ns) =>
                {
                    return BuildCellControl(columnName, cellFunc, node);
                }, true),
                null,
                GetGridLength(columnWidth),
                new TemplateColumnOptions<T>
                {
                    CompareAscending = Sort(comparer, false),
                    CompareDescending = Sort(comparer, true)
                })
            {
                Tag = columnName,
            };

For the first column, the grid length is new GridLength(1, GridUnitType.Star); And for the other two it's new GridLength(100, GridUnitType.Pixel);

Also, the TreeDataGrid is inside a non-resizable Window; it has a fixed width, and these two options:

            CanResize = false;
            SizeToContent = SizeToContent.Height;
berruezo commented 10 months ago

I saw that when executing a LayoutPass on the TreeDataGrid the Bounds.Size is 0,0.

image

The EffectiveViewport.Size is correct, but the Intersect operation is causing the Viewport to be of size 0,0 as well, and thus using a wrong availableWidth when calculating the star width.

image

On the previous version, the Bounds.Size was correct, and the Viewport was not empty when exiting this method. Is this of any help?

grokys commented 10 months ago

Ok, the missing part was that the TreeDataGrid needs to have no items for this to repro. Fix incoming.