Skip to content

Commit 52d3ae7

Browse files
committed
Require scroll-to-bottom before accepting license agreement dialog
1 parent 3ca5861 commit 52d3ae7

1 file changed

Lines changed: 50 additions & 1 deletion

File tree

CollapseLauncher/XAMLs/MainApp/Pages/Dialogs/SimpleDialogs.cs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1910,7 +1910,56 @@ void HomepageHyperlinkOnClick(Hyperlink sender, HyperlinkClickEventArgs args)
19101910
closeText: Locale.Current.Lang?._Misc?.IDoNotAcceptAgreement,
19111911
primaryText: Locale.Current.Lang?._Misc?.IAcceptAgreement,
19121912
defaultButton: ContentDialogButton.Primary,
1913-
dialogTheme: ContentDialogTheme.Informational);
1913+
dialogTheme: ContentDialogTheme.Informational,
1914+
onLoaded: (sender, _) =>
1915+
{
1916+
if (sender is not ContentDialog dialog)
1917+
return;
1918+
1919+
// Disable the primary ("I accept") button until user scrolls to the bottom
1920+
dialog.IsPrimaryButtonEnabled = false;
1921+
1922+
// The ContentDialog wraps its Content in a ScrollViewer.
1923+
// Find it and listen for scroll changes.
1924+
ScrollViewer? sv = dialog.FindDescendant<ScrollViewer>();
1925+
if (sv == null)
1926+
return;
1927+
1928+
sv.ViewChanged += OnViewChanged;
1929+
1930+
// If content is short enough to not need scrolling,
1931+
// enable the button after layout completes.
1932+
sv.SizeChanged += OnSizeChanged;
1933+
1934+
void OnSizeChanged(object s, SizeChangedEventArgs e)
1935+
{
1936+
if (s is not ScrollViewer scrollViewer)
1937+
return;
1938+
1939+
if (scrollViewer.ScrollableHeight < 1)
1940+
{
1941+
dialog.IsPrimaryButtonEnabled = true;
1942+
scrollViewer.ViewChanged -= OnViewChanged;
1943+
scrollViewer.SizeChanged -= OnSizeChanged;
1944+
}
1945+
}
1946+
1947+
void OnViewChanged(object s, ScrollViewerViewChangedEventArgs args)
1948+
{
1949+
if (args.IsIntermediate)
1950+
return;
1951+
1952+
if (s is not ScrollViewer scrollViewer)
1953+
return;
1954+
1955+
if (scrollViewer.VerticalOffset >= scrollViewer.ScrollableHeight - 40)
1956+
{
1957+
dialog.IsPrimaryButtonEnabled = true;
1958+
scrollViewer.ViewChanged -= OnViewChanged;
1959+
scrollViewer.SizeChanged -= OnSizeChanged;
1960+
}
1961+
}
1962+
});
19141963
if (result == ContentDialogResult.None)
19151964
{
19161965
return false;

0 commit comments

Comments
 (0)