public void SetTheme(FrameworkElement element)
        {
            if (element is Control control)
            {
                control.SetResourceReference(Control.BackgroundProperty, ThemedDialogColors.WindowPanelBrushKey);
                control.SetResourceReference(Control.ForegroundProperty, ThemedDialogColors.WindowPanelTextBrushKey);
                control.SetResourceReference(Control.BorderBrushProperty, ThemedDialogColors.WindowBorderBrushKey);
                control.SetResourceReference(TasExplorerView.ListItemMouseOverBrushProperty, ThemedDialogColors.ListItemMouseOverBrushKey);
                control.SetResourceReference(TasExplorerView.WizardFooterBrushProperty, ThemedDialogColors.WizardFooterBrushKey);
                control.SetResourceReference(DeploymentDialogView.HyperlinkBrushProperty, ThemedDialogColors.HyperlinkBrushKey);
                control.SetResourceReference(LoginView.HyperlinkBrushProperty, ThemedDialogColors.HyperlinkBrushKey);
                control.SetResourceReference(OutputView.ListItemMouseOverBrushProperty, ThemedDialogColors.ListItemMouseOverBrushKey);
                control.SetResourceReference(OutputView.WindowButtonDownBorderBrushProperty, ThemedDialogColors.WindowButtonDownBorderBrushKey);
                control.SetResourceReference(OutputView.WindowButtonDownHoverBrushProperty, ThemedDialogColors.WindowButtonHoverBrushKey);
                control.SetResourceReference(OutputView.WindowPanelBrushProperty, ThemedDialogColors.WindowPanelBrushKey);
            }

            ThemedDialogStyleLoader.SetUseDefaultThemedDialogStyles(element, true);
            ImageThemingUtilities.SetThemeScrollBars(element, true);
            if (!element.IsInitialized)
            {
                element.Initialized += OnElementInitialized;
            }
            else
            {
                MergeStyles(element);
            }
        }
        private static void UseVsThemePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (!DesignerProperties.GetIsInDesignMode(d))
            {
                if (d is FrameworkElement element)
                {
                    if ((bool)e.NewValue)
                    {
                        OverrideProperty(element, Control.BackgroundProperty, _originalBackgroundProperty, ThemedDialogColors.WindowPanelBrushKey);
                        OverrideProperty(element, Control.ForegroundProperty, _originalForegroundProperty, ThemedDialogColors.WindowPanelTextBrushKey);
                        ThemedDialogStyleLoader.SetUseDefaultThemedDialogStyles(element, true);
                        ImageThemingUtilities.SetThemeScrollBars(element, true);

                        // Only merge the styles after the element has been initialized.
                        // If the element hasn't been initialized yet, add an event handler
                        // so that we can merge the styles once it has been initialized.
                        if (!element.IsInitialized)
                        {
                            element.Initialized += OnElementInitialized;
                        }
                        else
                        {
                            MergeStyles(element);
                        }
                    }
                    else
                    {
                        if (_themeResources is not null)
                        {
                            element.Resources.MergedDictionaries.Remove(_themeResources);
                        }
                        ImageThemingUtilities.SetThemeScrollBars(element, null);
                        ThemedDialogStyleLoader.SetUseDefaultThemedDialogStyles(element, false);
                        RestoreProperty(element, Control.ForegroundProperty, _originalForegroundProperty);
                        RestoreProperty(element, Control.BackgroundProperty, _originalBackgroundProperty);
                    }
                }
            }
        }