Currently if I add an item to DataGrid, it will vertically resize itself if it's in a StackPanel, but not if it's in a Grid that has it's RowDefinitions set to Auto. Unfortunately, StackPanel's don't have enough sizing controls so aren't really an option. However, this does show the DataGrid is resizing correctly.
I'm guessing this is because the Grid.MeasureOverride function might be caching these sizes forever? Is there any way to invalidate the size, either automatically or manually?
https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Controls/Grid.cs#L315
I've created a test project here that illustrates this problem:
https://github.com/garyhertel/AvaloniaDataGridTestResizeOnAdd
(clicking on the background adds a new row, which will cause the DataGrid to scroll for the default Grid version, or resize the DataGrid if the StackPanel is enabled)
The WPF version of my project doesn't have this problem, so it would be nice to get some matching behavior.
I don't think this has anything to do with DataGrid itself. This is probably because of a known bug within the Grid implementation.
Yeah, I'm guessing this probably would happen for any control that changes it desired size after loading (like a hidden text box that becomes visible later). I'm working around it right now by manually setting the DataGrid height when the row count changes. Not ideal, but it works well enough for now.
I can confirm that the same problem happens for an item which becomes visible via binding. The Grid containing the item does not resize itself automatically, instead, whenever a resize happens to the Window containing both of them, the size gets adjusted properly. Here is an example XAML:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button Content="Some Progress" Margin="0,0,0,10"/>
<ProgressBar Grid.Row="1" Value="{Binding Progress}"
IsVisible="{Binding IsRunning}"/>
</Grid>
I'm running my app on Windows 10, and using the latest AvaloniaUI package (version 0.9.2).
Thank you guys for all the efforts!
There is no AffectsParentMeasure call for Visibility so changing the visibility isn't invalidating the Grid. I think we also have to subscribe to a child's size changes if it is in an auto column.
At this time, I would say it's better to have the bug label for the Grid itself, rather than DataGrid.
Hmm.. i wonder what should we do with this, on one hand we can try having some kind of invalidation but that might kill perf... Perhaps adding some logic on Grid's arrange method might do the trick.