private static object TryGetResource(ControlzEx.Theming.Theme theme, string key) { if (theme == null) { // nothing to do here, we can't find an app style (make sure all custom themes are added!) return(null); } object themeResource = theme.Resources[key]; return(themeResource); }
internal void ChangeFlyoutTheme(ControlzEx.Theming.Theme windowTheme) { // Beware: Über-dumb code ahead! switch (this.Theme) { case FlyoutTheme.Accent: ThemeManager.Current.ApplyThemeResourcesFromTheme(this.Resources, windowTheme); this.OverrideFlyoutResources(this.Resources, true); break; case FlyoutTheme.Adapt: ThemeManager.Current.ApplyThemeResourcesFromTheme(this.Resources, windowTheme); this.OverrideFlyoutResources(this.Resources); break; case FlyoutTheme.Inverse: var inverseTheme = ThemeManager.Current.GetInverseTheme(windowTheme); if (inverseTheme == null) { throw new InvalidOperationException("The inverse flyout theme only works if the window theme abides the naming convention. " + "See ThemeManager.GetInverseAppTheme for more infos"); } ThemeManager.Current.ApplyThemeResourcesFromTheme(this.Resources, inverseTheme); this.OverrideFlyoutResources(this.Resources); break; case FlyoutTheme.Dark: ThemeManager.Current.ApplyThemeResourcesFromTheme(this.Resources, windowTheme.BaseColorScheme == ThemeManager.BaseColorDark ? windowTheme : ThemeManager.Current.GetInverseTheme(windowTheme)); this.OverrideFlyoutResources(this.Resources); break; case FlyoutTheme.Light: ThemeManager.Current.ApplyThemeResourcesFromTheme(this.Resources, windowTheme.BaseColorScheme == ThemeManager.BaseColorLight ? windowTheme : ThemeManager.Current.GetInverseTheme(windowTheme)); this.OverrideFlyoutResources(this.Resources); break; } }
public static void AddDaxStudioAccentColor(this Application app) { // Fluent Dark Theme var dictGeneric = new ResourceDictionary() { Source = new Uri("pack://application:,,,/Fluent;component/Themes/Generic.xaml", UriKind.Absolute) }; app.Resources.MergedDictionaries.Add(dictGeneric); //var dictDark = new ResourceDictionary() //{ // Source = new Uri("pack://application:,,,/Fluent;component/Themes/Colors/BaseDark.xaml", UriKind.Absolute) //}; //app.Resources.MergedDictionaries.Add(dictDark); //var dictAccent = new ResourceDictionary() //{ // Source = new Uri("pack://application:,,,/Fluent;component/Themes/Accents/Green.xaml", UriKind.Absolute) //}; //app.Resources.MergedDictionaries.Add(dictAccent); // add custom accent and theme resource dictionaries to the ThemeManager var source = new Uri("pack://application:,,,/DaxStudio.UI;component/Theme/Light.DaxStudio.xaml"); var lightTheme = new ControlzEx.Theming.Theme(new LibraryTheme(source, null)); ThemeManager.Current.AddTheme(lightTheme); source = new Uri("pack://application:,,,/DaxStudio.UI;component/Theme/Dark.DaxStudio.xaml"); var darkTheme = new ControlzEx.Theming.Theme(new LibraryTheme(source, null)); ThemeManager.Current.AddTheme(darkTheme); // get the current theme from the application var theme = ThemeManager.Current.DetectTheme(Application.Current); }
private static void ChangeAllWindowButtonCommandsBrush(this MetroWindow window, Brush foregroundBrush, ControlzEx.Theming.Theme currentAppTheme, FlyoutTheme flyoutTheme = FlyoutTheme.Adapt, Position position = Position.Top) { if (position == Position.Right || position == Position.Top) { if (foregroundBrush == null) { window.WindowButtonCommands?.ClearValue(Control.ForegroundProperty); } // set the theme based on color lightness // otherwise set the theme based on current application or window theme var theme = currentAppTheme != null && currentAppTheme.BaseColorScheme == ThemeManager.BaseColorDark ? ThemeManager.BaseColorDark : ThemeManager.BaseColorLight; if (flyoutTheme == FlyoutTheme.Light) { theme = ThemeManager.BaseColorLight; } else if (flyoutTheme == FlyoutTheme.Dark) { theme = ThemeManager.BaseColorDark; } else if (flyoutTheme == FlyoutTheme.Inverse) { theme = theme == ThemeManager.BaseColorLight ? ThemeManager.BaseColorDark : ThemeManager.BaseColorLight; } window.WindowButtonCommands?.SetValue(WindowButtonCommands.ThemeProperty, theme); // clear or set the foreground property if (foregroundBrush != null) { window.WindowButtonCommands?.SetValue(Control.ForegroundProperty, foregroundBrush); } } }
private static void ChangeAllWindowCommandsBrush(this MetroWindow window, Brush foregroundBrush, ControlzEx.Theming.Theme currentAppTheme) { if (foregroundBrush == null) { window.LeftWindowCommands?.ClearValue(Control.ForegroundProperty); window.RightWindowCommands?.ClearValue(Control.ForegroundProperty); } // set the theme based on current application or window theme var theme = currentAppTheme != null && currentAppTheme.BaseColorScheme == ThemeManager.BaseColorDark ? ThemeManager.BaseColorDark : ThemeManager.BaseColorLight; // set the theme to light by default window.LeftWindowCommands?.SetValue(WindowCommands.ThemeProperty, theme); window.RightWindowCommands?.SetValue(WindowCommands.ThemeProperty, theme); // clear or set the foreground property if (foregroundBrush != null) { window.LeftWindowCommands?.SetValue(Control.ForegroundProperty, foregroundBrush); window.RightWindowCommands?.SetValue(Control.ForegroundProperty, foregroundBrush); } }