DetectTheme() private static méthode

private static DetectTheme ( DependencyObject dialog ) : Accent>.Tuple
dialog System.Windows.DependencyObject
Résultat Accent>.Tuple
Exemple #1
0
        private void HandleTheme()
        {
            if (this.DialogSettings != null)
            {
                Tuple <AppTheme, Accent> tuple = BaseMetroDialog.DetectTheme(this);
                if (DesignerProperties.GetIsInDesignMode(this) || tuple == null)
                {
                    return;
                }
                AppTheme item1 = tuple.Item1;
                Accent   item2 = tuple.Item2;
                switch (this.DialogSettings.ColorScheme)
                {
                case MetroDialogColorScheme.Theme:
                {
                    ThemeManager.ChangeAppStyle(base.Resources, item2, item1);
                    DependencyProperty backgroundProperty = Control.BackgroundProperty;
                    Window             owningWindow       = this.OwningWindow;
                    if (owningWindow == null)
                    {
                        owningWindow = Application.Current.MainWindow;
                    }
                    base.SetValue(backgroundProperty, ThemeManager.GetResourceFromAppStyle(owningWindow, "WhiteColorBrush"));
                    DependencyProperty foregroundProperty = Control.ForegroundProperty;
                    Window             mainWindow         = this.OwningWindow;
                    if (mainWindow == null)
                    {
                        mainWindow = Application.Current.MainWindow;
                    }
                    base.SetValue(foregroundProperty, ThemeManager.GetResourceFromAppStyle(mainWindow, "BlackBrush"));
                    break;
                }

                case MetroDialogColorScheme.Accented:
                {
                    ThemeManager.ChangeAppStyle(base.Resources, item2, item1);
                    DependencyProperty dependencyProperty = Control.BackgroundProperty;
                    Window             window             = this.OwningWindow;
                    if (window == null)
                    {
                        window = Application.Current.MainWindow;
                    }
                    base.SetValue(dependencyProperty, ThemeManager.GetResourceFromAppStyle(window, "HighlightBrush"));
                    DependencyProperty foregroundProperty1 = Control.ForegroundProperty;
                    Window             owningWindow1       = this.OwningWindow;
                    if (owningWindow1 == null)
                    {
                        owningWindow1 = Application.Current.MainWindow;
                    }
                    base.SetValue(foregroundProperty1, ThemeManager.GetResourceFromAppStyle(owningWindow1, "IdealForegroundColorBrush"));
                    break;
                }

                case MetroDialogColorScheme.Inverted:
                {
                    AppTheme inverseAppTheme = ThemeManager.GetInverseAppTheme(item1);
                    if (inverseAppTheme == null)
                    {
                        throw new InvalidOperationException("The inverse dialog theme only works if the window theme abides the naming convention. See ThemeManager.GetInverseAppTheme for more infos");
                    }
                    ThemeManager.ChangeAppStyle(base.Resources, item2, inverseAppTheme);
                    DependencyProperty backgroundProperty1 = Control.BackgroundProperty;
                    Window             mainWindow1         = this.OwningWindow;
                    if (mainWindow1 == null)
                    {
                        mainWindow1 = Application.Current.MainWindow;
                    }
                    base.SetValue(backgroundProperty1, ThemeManager.GetResourceFromAppStyle(mainWindow1, "BlackColorBrush"));
                    DependencyProperty dependencyProperty1 = Control.ForegroundProperty;
                    Window             window1             = this.OwningWindow;
                    if (window1 == null)
                    {
                        window1 = Application.Current.MainWindow;
                    }
                    base.SetValue(dependencyProperty1, ThemeManager.GetResourceFromAppStyle(window1, "WhiteColorBrush"));
                    break;
                }
                }
            }
            if (this.ParentDialogWindow != null)
            {
                this.ParentDialogWindow.SetValue(Control.BackgroundProperty, base.Background);
                Window owningWindow2 = this.OwningWindow;
                if (owningWindow2 == null)
                {
                    owningWindow2 = Application.Current.MainWindow;
                }
                object resourceFromAppStyle = ThemeManager.GetResourceFromAppStyle(owningWindow2, "AccentColorBrush");
                if (resourceFromAppStyle != null)
                {
                    this.ParentDialogWindow.SetValue(MetroWindow.GlowBrushProperty, resourceFromAppStyle);
                }
            }
        }