How to scroll to the bottom of a ScrollViewer automatically with Xaml and binding?

前端 未结 6 1593
一生所求
一生所求 2020-12-01 05:57

I\'ve got a TextBlock whose content is data bound to a string property of the ViewModel. This TextBlock has a ScrollViewer wrapped aro

6条回答
  •  醉酒成梦
    2020-12-01 06:47

    I was using @Roy T. 's answer, however I wanted the added stipulation that if you scrolled back in time, but then added text, the scroll view should auto scroll to bottom.

    I used this:

    private static void ScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e)
    {
        var scrollViewer = sender as ScrollViewer;
    
        if (e.ExtentHeightChange > 0)
        {
            scrollViewer.ScrollToEnd();
        }    
    }
    

    in place of the SizeChanged event.

提交回复
热议问题