Search code examples
c#wpfscrollviewer

What is the difference between ScrollViewer.ScrollToEnd() and ScrollViewer.ScrollToBottom()?


Does anyone know what is the difference between ScrollViewer.ScrollToEnd() and ScrollViewer.ScrollToBottom()?

In Visual Studio 2022, the description of ScrollToEnd() and ScrollToBottom() is the same: "Scrolls vertically to the end of ScrollViewer content."

Nevertheless, there must be a difference, otherwise there would not exist both.

Thanks for your answers!


Solution

  • ScrollToBottom() scrolls to the bottommost Y coordinate, but does not change the horizontal offset. Thus this method only changes the current Y offset.

    ScrollToEnd() scrolls to both the bottommost Y coordinate AND the rightmost X coordinate. Thus this method changes both the current Y AND the current X coordinates.

    Note that in many cases like this, if you're unsure what the code does you can look at the implementation on https://source.dot.net/

    For this particular case: https://source.dot.net/#PresentationFramework/System/Windows/Controls/ScrollViewer.cs,488ab4a977a015eb

    However, the documentation does actually specify the behaviour for these methods:

    https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.scrollviewer.scrolltoend?view=windowsdesktop-6.0

    The naming of those two methods is not great. It might have been better to call them ScrollToBottom() and ScrollToBottomRight() and then it would have been more obvious (IMO).