Open aguahombre opened 4 years ago
This only occurs if one of the column headers is longer than the column contents.
So your Grid grows in size. That's why your Scrollbar grows
No, the header exists before the row is added. The new row added does NOT increase or change the scroll area width.
I added some diagnostics and can see that the ScrollViewer is calling LayoutUpdated twice for every add click. The first time with an incorrect smaller width, the second with the correct width.
The first update with incorrect width is causing the scroll bar to move left.
You are defining Grid.IsSharedSizeScope="True"
on the ScrollViewer so all Grids within that ScrollViewer share the column width when they have the same SharedSizeGroup. If you add an item that doesn't fit into the column the group is resized so the newly added content fits into the column. So items added to your header can resize the group and items added to your ItemsControl can resize the group.
Understood, but as I said, the add row does not change the width of any of the columns once the header and first item rows are present as per the images. All the added item rows have shared columns with the same widths 30, 20, 5, 10, 15 characters respectively. Only the header row differs from the item rows and this is the first row in the shared scope. It is the 2nd and subsequent adds that cause the unwanted scrolling.
FYI I ported the code back to WPF and you don't get the erroneous scroll left on add.
I added diagnostics output to the scroll viewers PropertyChanged event.
private void _scrollViewer_PropertyChanged(object sender, Avalonia.AvaloniaPropertyChangedEventArgs e)
{
System.Diagnostics.Debug.WriteLine($"ScrollViewer.PropertyChanged {e.Property} {e.OldValue} -> {e.NewValue}");
}
This clearly shows that the Extent property is being set twice per add. The first set with the wrong extent causes the scroll bar to move left.
Add
ScrollViewer.PropertyChanged Extent 916, 300 -> 829, 300
ScrollViewer.PropertyChanged HorizontalScrollBarMaximum 0 -> 329
ScrollViewer.PropertyChanged Offset 416, 0 -> 329, 0
ScrollViewer.PropertyChanged HorizontalScrollBarMaximum 0 -> 329
ScrollViewer.PropertyChanged HorizontalScrollBarValue 0 -> 329
ScrollViewer.PropertyChanged HorizontalScrollBarViewportSize 0 -> 500
ScrollViewer.PropertyChanged VerticalScrollBarMaximum 0 -> 0
ScrollViewer.PropertyChanged VerticalScrollBarValue 0 -> 0
ScrollViewer.PropertyChanged VerticalScrollBarViewportSize 0 -> 300
ScrollViewer.PropertyChanged HorizontalScrollBarValue 416 -> 329
ScrollViewer.PropertyChanged HorizontalScrollBarValue 0 -> 329
ScrollViewer.PropertyChanged HorizontalScrollBarViewportSize 0 -> 500
ScrollViewer.PropertyChanged VerticalScrollBarMaximum 0 -> 0
ScrollViewer.PropertyChanged VerticalScrollBarValue 0 -> 0
ScrollViewer.PropertyChanged VerticalScrollBarViewportSize 0 -> 300
ScrollViewer.LayoutUpdated 500, 80
ScrollViewer.PropertyChanged Extent 829, 300 -> 916, 300
ScrollViewer.PropertyChanged HorizontalScrollBarMaximum 0 -> 416
ScrollViewer.PropertyChanged HorizontalScrollBarValue 0 -> 329
ScrollViewer.PropertyChanged HorizontalScrollBarViewportSize 0 -> 500
ScrollViewer.PropertyChanged VerticalScrollBarMaximum 0 -> 0
ScrollViewer.PropertyChanged VerticalScrollBarValue 0 -> 0
ScrollViewer.PropertyChanged VerticalScrollBarViewportSize 0 -> 300
I have seen a similar problem when scrolling a ItemsControl containing Grids with SharedSizeGroups.
Avalonia 0.9.3 I have a ItemsControl containing Grids with several columns with shared width implemented using via SharedSizeGroup inside a scroll viewer. If I scroll to the right limit and then add a new item to the list, the view scrolls a bit to the left. Why? The width of the scroll area has not changed so I would expect the view to remain scrolled to the right limit. This only occurs if one of the column headers is longer than the column contents.
Before Add
After Add
Repo: XAML
And the code behind