How do you scroll to the bottom of a TextBox for a UWP app?
With my transition to UWP, this has been one of the questions that hasn\'t been straight-forward.
An equivalent to the previous answer in C++/CX:
using Windows::UI::Xaml::Media::VisualTreeHelper;
using Windows::UI::Xaml::Controls::Grid;
using Windows::UI::Xaml::Controls::ScrollViewer;
using Platform::Object;
void
MainPage::responseTextUpdated(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Grid^ grid = static_cast(VisualTreeHelper::GetChild(responseText, 0));
for (int i = 0; i < VisualTreeHelper::GetChildrenCount(grid); ++i)
{
Object^ child = VisualTreeHelper::GetChild(grid, i);
ScrollViewer^ scrollViewer = dynamic_cast(child);
if (scrollViewer == nullptr) continue;
double const horizontalOffset = 0;
double const verticalOffset = scrollViewer->ExtentHeight;
float const zoomFactor = 1;
scrollViewer->ChangeView(horizontalOffset, verticalOffset, zoomFactor);
break;
}
}
Where responseText is TextBox^ responseText, the TextBox you want to scroll (probably the same as sender).