From 29be8564f6ab4c34b46abd8099adbd02286574d1 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Mon, 16 Aug 2021 08:41:17 -0500 Subject: [PATCH] Manually dismiss popups when the window moves, or the SUI scrolls (#10922) ## Summary of the Pull Request BODGY! This solution was suggested in https://github.com/microsoft/microsoft-ui-xaml/issues/4554#issuecomment-887815332. When the window moves, or when a ScrollViewer scrolls, dismiss any popups that are visible. This happens automagically when an app is a real XAML app, but it doesn't work for XAML Islands. ## References * upstream at https://github.com/microsoft/microsoft-ui-xaml/issues/4554 ## PR Checklist * [x] Closes #9320 * [x] I work here * [ ] Tests added/passed * [ ] Requires documentation to be updated ## Detailed Description of the Pull Request / Additional comments Unfortunately, we've got a bunch of scroll viewers in our SUI. So I did something bodgyx2 to make our life a little easier. `DismissAllPopups` can be used to dismiss all popups for a particular UI element. However, we've got a bunch of pages with scroll viewers that may or may not have popups in them. Rather than define the same exact body for all their `ViewChanging` events, the `HasScrollViewer` struct will just do it for you! Inside the `HasScrollViewer` stuct, we can't get at the `XamlRoot()` that our subclass implements. I mean, _we_ can, but when XAML does it's codegen, _XAML_ won't be able to figure it out. Fortunately for us, we don't need to! The sender is a UIElement, so we can just get _their_ `XamlRoot()`. So, you can fix this for any SUI page with just a simple ```diff - + ``` ```diff - struct AddProfile : AddProfileT + struct AddProfile : public HasScrollViewer, AddProfileT ``` ## Validation Steps Performed * the window doesn't close when you move it * the popups _do_ close when you move the window * the popups close when you scroll any SUI page --- src/cascadia/TerminalSettingsEditor/Actions.h | 2 +- .../TerminalSettingsEditor/Actions.xaml | 2 +- .../TerminalSettingsEditor/AddProfile.h | 2 +- .../TerminalSettingsEditor/AddProfile.xaml | 2 +- .../TerminalSettingsEditor/ColorSchemes.h | 2 +- .../TerminalSettingsEditor/ColorSchemes.xaml | 2 +- .../TerminalSettingsEditor/GlobalAppearance.h | 2 +- .../GlobalAppearance.xaml | 2 +- .../TerminalSettingsEditor/Interaction.h | 2 +- .../TerminalSettingsEditor/Interaction.xaml | 2 +- src/cascadia/TerminalSettingsEditor/Launch.h | 2 +- .../TerminalSettingsEditor/Launch.xaml | 2 +- .../TerminalSettingsEditor/Profiles.h | 2 +- .../TerminalSettingsEditor/Profiles.xaml | 6 +- .../TerminalSettingsEditor/ReadOnlyActions.h | 2 +- .../ReadOnlyActions.xaml | 2 +- .../TerminalSettingsEditor/Rendering.h | 2 +- .../TerminalSettingsEditor/Rendering.xaml | 2 +- src/cascadia/TerminalSettingsEditor/Utils.h | 38 +++ src/cascadia/WindowsTerminal/AppHost.cpp | 27 ++ src/cascadia/WindowsTerminal/AppHost.h | 1 + src/cascadia/WindowsTerminal/IslandWindow.cpp | 5 + src/cascadia/WindowsTerminal/IslandWindow.h | 273 +++++++++--------- src/cascadia/WindowsTerminal/pch.h | 2 + 24 files changed, 231 insertions(+), 155 deletions(-) diff --git a/src/cascadia/TerminalSettingsEditor/Actions.h b/src/cascadia/TerminalSettingsEditor/Actions.h index 9c4d37cf6..97ae3d58b 100644 --- a/src/cascadia/TerminalSettingsEditor/Actions.h +++ b/src/cascadia/TerminalSettingsEditor/Actions.h @@ -107,7 +107,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation WINRT_PROPERTY(Model::CascadiaSettings, Settings, nullptr) }; - struct Actions : ActionsT + struct Actions : public HasScrollViewer, ActionsT { public: Actions(); diff --git a/src/cascadia/TerminalSettingsEditor/Actions.xaml b/src/cascadia/TerminalSettingsEditor/Actions.xaml index 11c1f65e4..35a59cc8f 100644 --- a/src/cascadia/TerminalSettingsEditor/Actions.xaml +++ b/src/cascadia/TerminalSettingsEditor/Actions.xaml @@ -374,7 +374,7 @@ - + diff --git a/src/cascadia/TerminalSettingsEditor/AddProfile.h b/src/cascadia/TerminalSettingsEditor/AddProfile.h index 39b78ffe9..5eaedbbad 100644 --- a/src/cascadia/TerminalSettingsEditor/AddProfile.h +++ b/src/cascadia/TerminalSettingsEditor/AddProfile.h @@ -43,7 +43,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation WINRT_CALLBACK(AddNew, AddNewArgs); }; - struct AddProfile : AddProfileT + struct AddProfile : public HasScrollViewer, AddProfileT { public: AddProfile(); diff --git a/src/cascadia/TerminalSettingsEditor/AddProfile.xaml b/src/cascadia/TerminalSettingsEditor/AddProfile.xaml index 5cff69b87..6229512c6 100644 --- a/src/cascadia/TerminalSettingsEditor/AddProfile.xaml +++ b/src/cascadia/TerminalSettingsEditor/AddProfile.xaml @@ -21,7 +21,7 @@ - +