Search code examples
c#windows-8windows-runtimescrolltextblock

WinRT c# - Text Block scroll auto to the end


I would like to scroll auto to the end of a textblock if I add text to it. But I try a lot of thing, but I failed hard.

Anybody has a good idea to do this on a WinRT application ?

Thanks for your time, regards.


Solution

    • Step 1 - Get WinRT XAML Toolkit from NuGet
    • Step 2 - Add following using to your code

      using WinRTXamlToolkit.Controls.Extensions;
      
    • Step 3 - Make following call after you add (replace really) the Text in the TextBox

      var scrollViewer = textBlock.GetFirstDescendantOfType<ScrollViewer>();
      scrollViewer.ScrollToVerticalOffset(scrollViewer.ScrollableHeight);