diff --git a/Sample Applications/WPFGallery/Views/BasicInput/ComboBoxPage.xaml.cs b/Sample Applications/WPFGallery/Views/BasicInput/ComboBoxPage.xaml.cs index d8aba374..a9cbaff5 100644 --- a/Sample Applications/WPFGallery/Views/BasicInput/ComboBoxPage.xaml.cs +++ b/Sample Applications/WPFGallery/Views/BasicInput/ComboBoxPage.xaml.cs @@ -1,7 +1,11 @@ -using System.Windows.Documents; +using System.Windows; +using System.Windows.Documents; +using System.Windows.Media; using System.Windows.Navigation; using System.Windows.Shapes; +using Microsoft.Win32; + using WPFGallery.ViewModels; namespace WPFGallery.Views; @@ -19,5 +23,30 @@ public ComboBoxPage(ComboBoxPageViewModel viewModel) DataContext = this; InitializeComponent(); + + SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged; + this.Loaded += (s, e) => UpdatePageVisuals(); +} + +private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e) +{ + Dispatcher.Invoke(() => + { + UpdatePageVisuals(); + }); +} + +private void UpdatePageVisuals() +{ + // Fluent's HC selection color is WindowColor, washing out editable text selected on focus; use the Highlight color instead. + // Re-evaluated on theme changes so switching out of high contrast reverts to the theme default. + if (SystemParameters.HighContrast) + { + Resources["TextControlSelectionHighlightColor"] = new SolidColorBrush(SystemColors.HighlightColor); + } + else + { + Resources.Remove("TextControlSelectionHighlightColor"); + } } }