コード例 #1
0
        internal void Update(string themeKey)
        {
            if (ThemeDictionaries.TryGetValue(themeKey, out ResourceDictionary themeDictionary))
            {
                if (_mergedThemeDictionary != null)
                {
                    if (_mergedThemeDictionary == themeDictionary)
                    {
                        return;
                    }
                    else
                    {
                        int targetIndex = MergedDictionaries.IndexOf(_mergedThemeDictionary);
                        MergedDictionaries[targetIndex] = themeDictionary;
                        _mergedThemeDictionary          = themeDictionary;
                    }
                }
                else
                {
                    int targetIndex;

                    if (MergedAppThemeDictionary != null)
                    {
                        targetIndex = MergedDictionaries.IndexOf(MergedAppThemeDictionary) + 1;
                    }
                    else
                    {
                        targetIndex = 0;
                    }

                    MergedDictionaries.Insert(targetIndex, themeDictionary);
                    _mergedThemeDictionary = themeDictionary;
                }
            }
            else
            {
                if (_mergedThemeDictionary != null)
                {
                    MergedDictionaries.Remove(_mergedThemeDictionary);
                    _mergedThemeDictionary = null;
                }
            }
        }
コード例 #2
0
        ResourceDictionary GetTheme(string color, string accent)
        {
            string themeName = string.Format("NoesisTheme.Brushes.{0}{1}.xaml", color, accent);

            ResourceDictionary theme;

            if (ThemeDictionaries.TryGetValue(themeName, out theme))
            {
                return(theme);
            }

            Uri uri = new Uri("pack://application:,,,/Noesis.GUI.Extensions;component/Theme/" + themeName, UriKind.RelativeOrAbsolute);

            theme = new ResourceDictionary {
                Source = uri
            };
            ThemeDictionaries.Add(themeName, theme);

            return(theme);
        }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: pdan1/Tutorials
        ResourceDictionary GetTheme(string color, string accent)
        {
            string themeName = string.Format("NoesisTheme.Brushes.{0}{1}.xaml", color, accent);

            ResourceDictionary theme;

            if (ThemeDictionaries.TryGetValue(themeName, out theme))
            {
                return(theme);
            }

            Uri uri = new Uri("Assets/NoesisGUI/Theme/" + themeName, UriKind.Relative);

            theme = new ResourceDictionary {
                Source = uri
            };
            ThemeDictionaries.Add(themeName, theme);

            return(theme);
        }
コード例 #4
0
 internal void Update(string themeKey)
 {
     if (ThemeDictionaries.TryGetValue(themeKey, out ResourceDictionary themeDictionary))
     {
         MergedDictionaries.InsertOrReplace(ContainsApplicationThemeDictionary ? 1 : 0, themeDictionary);
     }
     else
     {
         if (ContainsApplicationThemeDictionary)
         {
             Debug.Assert(MergedDictionaries.Count >= 1 && MergedDictionaries.Count <= 2);
             if (MergedDictionaries.Count == 2)
             {
                 MergedDictionaries.RemoveAt(1);
             }
         }
         else
         {
             MergedDictionaries.Clear();
         }
     }
 }