This should be the explanation from ScrollViewer Source Code:
If you call ScrollToBottom
a Double.PositiveInfinity
value will be set as VerticalOffset
.
/// <summary>
/// Vertically scroll to the end of the content.
/// </summary>
public void ScrollToBottom()
{
EnqueueCommand(Commands.SetVerticalOffset, Double.PositiveInfinity, null);
}
After adding a new item ScrollViewer
updates the view with the last VerticalOffset
which is still PositiveInfinity
meaning it scrolls again to the end. With
var verticalOffset = MessagesScrollViewer.VerticalOffset;
MessagesScrollViewer.ScrollToVerticalOffset(verticalOffset);
ScrollViewer
sets the real VerticalOffset
and all will be okay.