Match the RequestedTheme of our TeachingTips to the set theme (#9732)

## Summary of the Pull Request

Make sure that the window renamer and other toasts follow the requested app theme. We accomplish this by doing something similar to what we do with ContentDialogs. Since TeachingTips aren't in the same XAML root, we have to traverse the entire tree upwards setting RequestedTheme. If we don't, then we'll update the background color of the TeachingTip, but not the text inside it. 

## References
* Added in #9662 and #9523 

## PR Checklist
* [x] Closes #9717
* [x] I work here
* [n/a] Tests added/passed
* [n/a] Requires documentation to be updated

## Validation Steps Performed
Tested with system theme light & dark, and `theme` set to `light, dark, and unset, and verified that they worked as expected.
This commit is contained in:
Mike Griese 2021-04-07 10:27:41 -05:00 committed by GitHub
parent cdf2630204
commit 361877cf1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 0 deletions

View file

@ -736,6 +736,7 @@ namespace winrt::TerminalApp::implementation
}
}
_UpdateTeachingTipTheme(WindowRenamer().try_as<winrt::Windows::UI::Xaml::FrameworkElement>());
WindowRenamer().IsOpen(true);
// PAIN: We can't immediately focus the textbox in the TeachingTip. It's

View file

@ -2520,6 +2520,24 @@ namespace winrt::TerminalApp::implementation
}
}
// Method Description:
// - Update the RequestedTheme of the specified FrameworkElement and all its
// Parent elements. We need to do this so that we can actually theme all
// of the elements of the TeachingTip. See GH#9717
// Arguments:
// - element: The TeachingTip to set the theme on.
// Return Value:
// - <none>
void TerminalPage::_UpdateTeachingTipTheme(winrt::Windows::UI::Xaml::FrameworkElement element)
{
auto theme{ _settings.GlobalSettings().Theme() };
while (element)
{
element.RequestedTheme(theme);
element = element.Parent().try_as<winrt::Windows::UI::Xaml::FrameworkElement>();
}
}
// Method Description:
// - Display the name and ID of this window in a TeachingTip. If the window
// has no name, the name will be presented as "<unnamed-window>".
@ -2549,6 +2567,7 @@ namespace winrt::TerminalApp::implementation
tip.Closed({ page->get_weak(), &TerminalPage::_FocusActiveControl });
}
}
_UpdateTeachingTipTheme(WindowIdToast().try_as<winrt::Windows::UI::Xaml::FrameworkElement>());
if (page->_windowIdToast != nullptr)
{
@ -2642,6 +2661,7 @@ namespace winrt::TerminalApp::implementation
tip.Closed({ page->get_weak(), &TerminalPage::_FocusActiveControl });
}
}
_UpdateTeachingTipTheme(RenameFailedToast().try_as<winrt::Windows::UI::Xaml::FrameworkElement>());
if (page->_windowRenameFailedToast != nullptr)
{

View file

@ -327,6 +327,9 @@ namespace winrt::TerminalApp::implementation
void _WindowRenamerActionClick(const IInspectable& sender, const IInspectable& eventArgs);
void _RequestWindowRename(const winrt::hstring& newName);
void _WindowRenamerKeyUp(const IInspectable& sender, winrt::Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e);
void _UpdateTeachingTipTheme(winrt::Windows::UI::Xaml::FrameworkElement element);
#pragma region ActionHandlers
// These are all defined in AppActionHandlers.cpp
#define ON_ALL_ACTIONS(action) DECLARE_ACTION_HANDLER(action);