private void scrollviewer_Messages_ScrollChanged(object sender, ScrollChangedEventArgs e){ ScrollViewer scrollViewer = sender as ScrollViewer; if (e.ExtentHeightChange == 0) { // Content unchanged : user scroll event if (scrollViewer.VerticalOffset == scrollViewer.ScrollableHeight) { // Scroll bar is in bottom // Set auto-scroll mode AutoScroll = true; } else { // Scroll bar isn't in bottom // Unset auto-scroll mode AutoScroll = false; } } // Content scroll event : auto-scroll eventually if (AutoScroll && e.ExtentHeightChange != 0) { // Content changed and auto-scroll mode set // Autoscroll scrollViewer.ScrollToVerticalOffset(scrollViewer.ExtentHeight); }}
<ScrollViewer x:Name="MessageScroller" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" ScrollChanged="scrollviewer_Messages_ScrollChanged"> <ItemsPresenter /> </ScrollViewer>