public void SetTheme(string themeName, ThemeType themeType = ThemeType.Portal) { Theme theme = _themeRepository.Table.SingleOrDefault(t => t.ThemeType == themeType.ToString()); theme.ThemeName = themeName; theme.ThemeType = themeType.ToString(); _themeRepository.SubmitChanges(); Cache.Remove(CoreCacheKeys.ThemeKeys.ThemeByType(themeType)); }
/// <summary> /// Constructs an authorize url. /// </summary> public static string BuildAuthorizeUrl( string clientId, string redirectUrl, IEnumerable<string> scopes, ResponseType responseType, DisplayType display, ThemeType theme, string locale, string state) { Debug.Assert(!string.IsNullOrEmpty(clientId)); Debug.Assert(!string.IsNullOrEmpty(redirectUrl)); Debug.Assert(!string.IsNullOrEmpty(locale)); IDictionary<string, string> options = new Dictionary<string, string>(); options[AuthConstants.ClientId] = clientId; options[AuthConstants.Callback] = redirectUrl; options[AuthConstants.Scope] = BuildScopeString(scopes); options[AuthConstants.ResponseType] = responseType.ToString().ToLowerInvariant(); options[AuthConstants.Display] = display.ToString().ToLowerInvariant(); options[AuthConstants.Locale] = locale; options[AuthConstants.ClientState] = EncodeAppRequestState(state); if (theme != ThemeType.None) { options[AuthConstants.Theme] = theme.ToString().ToLowerInvariant(); } return BuildAuthUrl(AuthEndpointsInfo.AuthorizePath, options); }
/// <summary> /// Constructs an authorize url. /// </summary> public static string BuildAuthorizeUrl( string clientId, string redirectUrl, IEnumerable <string> scopes, ResponseType responseType, DisplayType display, ThemeType theme, string locale, string state) { Debug.Assert(!string.IsNullOrEmpty(clientId)); Debug.Assert(!string.IsNullOrEmpty(redirectUrl)); Debug.Assert(!string.IsNullOrEmpty(locale)); IDictionary <string, string> options = new Dictionary <string, string>(); options[AuthConstants.ClientId] = clientId; options[AuthConstants.Callback] = redirectUrl; options[AuthConstants.Scope] = BuildScopeString(scopes); options[AuthConstants.ResponseType] = responseType.ToString().ToLowerInvariant(); options[AuthConstants.Display] = display.ToString().ToLowerInvariant(); options[AuthConstants.Locale] = locale; options[AuthConstants.ClientState] = EncodeAppRequestState(state); if (theme != ThemeType.None) { options[AuthConstants.Theme] = theme.ToString().ToLowerInvariant(); } return(BuildAuthUrl(AuthEndpointsInfo.AuthorizePath, options)); }
/// <summary> /// 可以在配置文件进行设置 /// </summary> public void SetDefaultTheme(ThemeType type) { _currentTheme = type; _themeProvider = _themeProvider ?? new ThemeProvider(); var themeColor = _themeProvider.ThemeColors[type.ToString().ToLower()]; var parentDictionary = Application.Current.Resources; var primarySource = $"pack://application:,,,/{Assembly.GetExecutingAssembly().GetName().Name};component/ColorBox/{Enum.GetName(typeof(ThemeType),type)}_primary.xaml"; var primarySourceDictionary = new ResourceDictionary() { Source = new Uri(primarySource) }; Application.Current.Resources.MergedDictionaries.Add(primarySourceDictionary); var accentSource = $"pack://application:,,,/{Assembly.GetExecutingAssembly().GetName().Name};component/ColorBox/{Enum.GetName(typeof(ThemeType), type)}_accent.xaml"; var accentSourceDictionary = new ResourceDictionary() { Source = new Uri(accentSource) }; Application.Current.Resources.MergedDictionaries.Add(accentSourceDictionary); }
public string ConvertThemeToRealTitle(ThemeType theme) { var enumType = typeof(ThemeType); var memberInfos = enumType.GetMember(theme.ToString()); var enumValueMemberInfo = memberInfos.FirstOrDefault(m => m.DeclaringType == enumType); var valueAttributes = enumValueMemberInfo.GetCustomAttributes(typeof(ThemeAttribute), false); return ((ThemeAttribute) valueAttributes[0]).RealTitle; }
public void ChangeTheme(ThemeType theme) { if (dict == null) { dict = Application.Current.Resources.MergedDictionaries.First(); } // テーマをリソース・ディクショナリのソースに指定 string themeUri = String.Format("View/Themes/{0}Theme.xaml", theme.ToString()); dict.Source = new Uri(themeUri); }
//Loads one theme file into the config dictionary void LoadThemeFile(FileInfo file) { var config = file.OpenText(); var yaml = new YamlStream(); yaml.Load(config); //Examine the yaml file: var mapping = (YamlMappingNode)yaml.Documents[0].RootNode; foreach (var entry in mapping.Children) { var nodeName = ((YamlScalarNode)entry.Key).Value; if (string.IsNullOrEmpty(nodeName)) { Logger.LogError($"No Theme Type found for {nodeName}", Category.Themes); continue; } //Get the theme type from the node name ThemeType theme = (ThemeType)Enum.Parse(typeof(ThemeType), nodeName, true); //See if we have a list set up for this theme type if (!configs.ContainsKey(theme)) { configs.Add(theme, new List <ThemeConfig>()); } //Get all the config names and their settings associated with this Theme type in this file var settings = (YamlMappingNode)entry.Value; foreach (var c in settings.Children) { var cfg = new ThemeConfig(); cfg.themeType = theme; cfg.themeName = ((YamlScalarNode)c.Key).Value; //check to see if that name is already in use: var index = configs[theme].FindIndex(x => x.themeName == cfg.themeName); if (index == -1) { //Get all the setting values for this config var values = (YamlMappingNode)c.Value; foreach (var kvp in values) { //Load hex colors into Color if (kvp.Key.ToString().Contains("ImageColor")) { if (!ColorUtility.TryParseHtmlString(kvp.Value.ToString(), out cfg.imageColor)) { Logger.LogError($"Failed to parse html color {kvp.Value.ToString()}", Category.Themes); } } if (kvp.Key.ToString().Contains("TextColor")) { if (!ColorUtility.TryParseHtmlString(kvp.Value.ToString(), out cfg.textColor)) { Logger.LogError($"Failed to parse html color {kvp.Value.ToString()}", Category.Themes); } } } configs[theme].Add(cfg); } else { Logger.LogError($"There is already a config named {cfg.themeName} in {theme.ToString()}", Category.Themes); } } } }
public static string ThemeByType(ThemeType type) { return("ThemeType." + type.ToString()); }
public void SetCurrentTheme(ThemeType type) { if (type != _currentTheme) { _currentTheme = type; _themeProvider = _themeProvider ?? new ThemeProvider(); var themeColor = _themeProvider.ThemeColors[type.ToString().ToLower()]; var parentDictionary = Application.Current.Resources; foreach (var item in Enum.GetNames(typeof(AccentBrushes))) { var brush = parentDictionary[item] as SolidColorBrush; if (item.StartsWith("AccentLight")) { var animation = new ColorAnimation { From = brush.Color, To = SetBrushColor(0, item), Duration = new Duration(TimeSpan.FromMilliseconds(300)) }; brush.BeginAnimation(SolidColorBrush.ColorProperty, animation); continue; } if (item.StartsWith("AccentMid")) { var animation = new ColorAnimation { From = brush.Color, To = SetBrushColor(2, item), Duration = new Duration(TimeSpan.FromMilliseconds(300)) }; brush.BeginAnimation(SolidColorBrush.ColorProperty, animation); continue; } if (item.StartsWith("AccentDark")) { var animation = new ColorAnimation { From = brush.Color, To = SetBrushColor(3, item), Duration = new Duration(TimeSpan.FromMilliseconds(300)) }; brush.BeginAnimation(SolidColorBrush.ColorProperty, animation); continue; } Color SetBrushColor(int index, string name) { if (item.Contains("Foreground")) { return(themeColor.AccentColors.ToArray()[index].ForeColor); } else { return(themeColor.AccentColors.ToArray()[index].BackColor); } } } foreach (var item in Enum.GetNames(typeof(PrimaryBrushes))) { var brush = parentDictionary[item] as SolidColorBrush; if (item.StartsWith("PrimaryLight")) { var animation = new ColorAnimation { From = brush.Color, To = SetBrushColor(0, item), Duration = new Duration(TimeSpan.FromMilliseconds(300)) }; brush.BeginAnimation(SolidColorBrush.ColorProperty, animation); continue; } if (item.StartsWith("PrimaryMid")) { var animation = new ColorAnimation { From = brush.Color, To = SetBrushColor(4, item), Duration = new Duration(TimeSpan.FromMilliseconds(300)) }; brush.BeginAnimation(SolidColorBrush.ColorProperty, animation); continue; } if (item.StartsWith("PrimaryDark")) { var animation = new ColorAnimation { From = brush.Color, To = SetBrushColor(8, item), Duration = new Duration(TimeSpan.FromMilliseconds(300)) }; brush.BeginAnimation(SolidColorBrush.ColorProperty, animation); continue; } Color SetBrushColor(int index, string name) { if (name.Contains("Foreground")) { return(themeColor.PrimaryColors.ToArray()[index].ForeColor); } else { return(themeColor.PrimaryColors.ToArray()[index].BackColor); } } } var existingResourceDictionary = Application.Current.Resources.MergedDictionaries .Where(rd => rd.Source != null) .Where(rd => Regex.Match(rd.Source.OriginalString, @"(\/Resource;component\/ColorBox\/([a-z]+)_(accent)|(primary))").Success).ToList(); if (existingResourceDictionary.Any()) { foreach (var item in existingResourceDictionary) { Application.Current.Resources.MergedDictionaries.Remove(item); } } var primarySource = $"pack://application:,,,/{Assembly.GetExecutingAssembly().GetName().Name};component/ColorBox/{Enum.GetName(typeof(ThemeType), type)}_primary.xaml"; var primarySourceDictionary = new ResourceDictionary() { Source = new Uri(primarySource) }; Application.Current.Resources.MergedDictionaries.Add(primarySourceDictionary); var accentSource = $"pack://application:,,,/{Assembly.GetExecutingAssembly().GetName().Name};component/ColorBox/{Enum.GetName(typeof(ThemeType), type)}_accent.xaml"; var accentSourceDictionary = new ResourceDictionary() { Source = new Uri(primarySource) }; Application.Current.Resources.MergedDictionaries.Add(accentSourceDictionary); } }
public string GetTheme(ThemeType themeType = ThemeType.Portal) { var theme = AspectF.Define .Cache <Theme>(Cache, CoreCacheKeys.ThemeKeys.ThemeByType(themeType)) .Return <Theme>(() => _themeRepository.Table.SingleOrDefault(t => t.ThemeType == themeType.ToString())); return(theme.ThemeName); }
public static Theme LoadTheme(ThemeType type) { return(LoadTheme(type.ToString())); }
public static Theme GetTheme(ThemeType type) { return(GetTheme(type.ToString())); }
public void UpdateTheme(ThemeType theme) { ThemeManager.SetTheme(theme); Theme.Name = theme.ToString(); }