ScrollViewer.ScrollToEnd() seems not working
See original GitHub issueDescribe the bug
ScrollViewer.ScrollToEnd() method is not working, content still remains in the same position.
To Reproduce Steps to reproduce the behavior:
- Create a ScrollViewer
- Add some vertical contents to activate the vertical scroll bar
- Call ScrollViewer.ScrollToEnd()
- See the error
Expected behavior
ScrollViewer should go to the end of the content.
Screenshots
ScrollViewer’s style:
<Style Selector="ScrollViewer">
<Setter Property="Background"
Value="Transparent" />
<Setter Property="Template">
<ControlTemplate>
<Grid ColumnDefinitions="*,Auto" RowDefinitions="*,Auto">
<ScrollContentPresenter Name="PART_ContentPresenter"
Grid.Row="0"
Grid.Column="0"
Grid.RowSpan="2"
Grid.ColumnSpan="2"
Background="{TemplateBinding Background}"
CanHorizontallyScroll="{TemplateBinding CanHorizontallyScroll}"
CanVerticallyScroll="{TemplateBinding CanVerticallyScroll}"
Content="{TemplateBinding Content}"
Extent="{TemplateBinding Extent, Mode=TwoWay}"
Margin="{TemplateBinding Padding}"
Offset="{TemplateBinding Offset, Mode=TwoWay}"
Viewport="{TemplateBinding Viewport, Mode=TwoWay}">
<ScrollContentPresenter.GestureRecognizers>
<ScrollGestureRecognizer
CanHorizontallyScroll="{TemplateBinding CanHorizontallyScroll}"
CanVerticallyScroll="{TemplateBinding CanVerticallyScroll}" />
</ScrollContentPresenter.GestureRecognizers>
</ScrollContentPresenter>
<ScrollBar Name="PART_HorizontalScrollBar"
AllowAutoHide="{TemplateBinding AllowAutoHide}"
Orientation="Horizontal"
LargeChange="{Binding LargeChange.Width, RelativeSource={RelativeSource TemplatedParent}}"
SmallChange="{Binding SmallChange.Width, RelativeSource={RelativeSource TemplatedParent}}"
Maximum="{TemplateBinding HorizontalScrollBarMaximum}"
Value="{TemplateBinding HorizontalScrollBarValue, Mode=TwoWay}"
ViewportSize="{TemplateBinding HorizontalScrollBarViewportSize}"
Visibility="{TemplateBinding HorizontalScrollBarVisibility}"
Grid.Row="1"
Focusable="False" />
<ScrollBar Name="PART_VerticalScrollBar"
AllowAutoHide="{TemplateBinding AllowAutoHide}"
Orientation="Vertical"
LargeChange="{Binding LargeChange.Height, RelativeSource={RelativeSource TemplatedParent}}"
SmallChange="{Binding SmallChange.Height, RelativeSource={RelativeSource TemplatedParent}}"
Maximum="{TemplateBinding VerticalScrollBarMaximum}"
Value="{TemplateBinding VerticalScrollBarValue, Mode=TwoWay}"
ViewportSize="{TemplateBinding VerticalScrollBarViewportSize}"
Visibility="{TemplateBinding VerticalScrollBarVisibility}"
Grid.Column="1"
Focusable="False" />
<Panel x:Name="PART_ScrollBarsSeparator" Grid.Row="1" Grid.Column="1"
Background="{DynamicResource ScrollViewerScrollBarsSeparatorBackground}" />
</Grid>
</ControlTemplate>
</Setter>
</Style>
Desktop (please complete the following information):
- OS: Windows 11 22H2
- Version: Latest Avalonia nightly build
Issue Analytics
- State:
- Created 8 months ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Doing AutoScroll with ScrollViewer.ScrollToEnd() only ...
The cause of the problem is that ScrollToEnd() has nothing to do with autoscroll. This call just scrolls to the end and that...
Read more >ScrollView.scrollTo method not working · Issue #24531
Here is my solution to scrollTo() issue. In order to programmatically scroll, set scrollOverflowEnabled prop to true . <ScrollView ref={scroller ...
Read more >PageDown with ScrollViewer
Hi, In our app most of our screens/pages/frames fit within the limits of a maximized window and Vertical scrolling is not required. We...
Read more >[Solved] ScrollViewer ScrollToEnd Buggy - UI
I'm using it as scroll viewer for the chat portion of my game, to scroll chat messages… however it seems to be buggy....
Read more >ScrollViewer.ScrollToEnd Method (System.Windows. ...
This method scrolls to both the vertical and horizontal end points of the content. This method does not induce any scrolling behavior if...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Without an actual repro it’s difficult to say for sure, but indeed in your case it sounds like you will need a layout pass to complete before being able to scroll to the end. That’s not a bug, it’s simply how it works - the contents of the
ItemsControl
are updated on layout.That doesn’t mean that all cases of scrolling to the end require a layout pass however, so I think the PR should be closed.
Basically I have an ItemsControl in the ScrollViewer.
I’m calling ScrollViewer.ScrollToEnd() in the event where the items source of ItemsControl is changed. So it should be in the UI thread. If I only use ScrollToEnd() without Dispatcher priority the content will not refresh. So maybe is a bug or something related to virtualization?