From 96b64c0e2d98e26dd1a66df9a8536307d849730d Mon Sep 17 00:00:00 2001 From: T Paine Date: Tue, 17 Sep 2019 08:57:17 -0700 Subject: [PATCH] TabView: Fix for terminal handling scrollviewer load issue (#1339) --- dev/TabView/TabView.cpp | 16 +++++++++++----- dev/dll/SharedHelpers.cpp | 8 ++++++++ dev/inc/SharedHelpers.h | 2 ++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/dev/TabView/TabView.cpp b/dev/TabView/TabView.cpp index e410136e2e..521e1ca34a 100644 --- a/dev/TabView/TabView.cpp +++ b/dev/TabView/TabView.cpp @@ -237,14 +237,20 @@ void TabView::OnListViewLoaded(const winrt::IInspectable&, const winrt::RoutedEv SelectedIndex(listView.SelectedIndex()); SelectedItem(listView.SelectedItem()); - m_scrollViewer.set([this, listView]() { - auto scrollViewer = SharedHelpers::FindInVisualTreeByName(listView, L"ScrollViewer").as(); - if (scrollViewer) + auto scrollViewer = SharedHelpers::FindInVisualTreeByName(listView, L"ScrollViewer").as(); + m_scrollViewer.set(scrollViewer); + if (scrollViewer) + { + if (SharedHelpers::IsIsLoadedAvailable() && scrollViewer.IsLoaded()) + { + // This scenario occurs reliably for Terminal in XAML islands + OnScrollViewerLoaded(nullptr, nullptr); + } + else { m_scrollViewerLoadedRevoker = scrollViewer.Loaded(winrt::auto_revoke, { this, &TabView::OnScrollViewerLoaded }); } - return scrollViewer; - }()); + } } } diff --git a/dev/dll/SharedHelpers.cpp b/dev/dll/SharedHelpers.cpp index c0954982af..db99dd52d5 100644 --- a/dev/dll/SharedHelpers.cpp +++ b/dev/dll/SharedHelpers.cpp @@ -198,6 +198,14 @@ bool SharedHelpers::IsThemeShadowAvailable() return s_isThemeShadowAvailable; } +bool SharedHelpers::IsIsLoadedAvailable() +{ + static bool s_isAvailable = + IsRS5OrHigher() || + winrt::ApiInformation::IsPropertyPresent(L"Windows.UI.Xaml.FrameworkElement", L"IsLoaded"); + return s_isAvailable; +} + template bool SharedHelpers::IsAPIContractVxAvailable() { static bool isAPIContractVxAvailableInitialized = false; diff --git a/dev/inc/SharedHelpers.h b/dev/inc/SharedHelpers.h index 5b9f3cba55..6b3193fa44 100644 --- a/dev/inc/SharedHelpers.h +++ b/dev/inc/SharedHelpers.h @@ -55,6 +55,8 @@ class SharedHelpers static bool IsThemeShadowAvailable(); + static bool IsIsLoadedAvailable(); + // Actual OS version checks static bool IsAPIContractV9Available(); // 19H2 static bool IsAPIContractV8Available(); // 19H1