Ejemplo n.º 1
0
        public void Update(bool systemTheme = false)
        {
            try
            {
                // Because of Compact, UpdateSource may be executed twice, but there is a bug in XAML and manually clear theme dictionaries here:
                // Prior to RS5, when ResourceDictionary.Source property is changed, XAML forgot to clear ThemeDictionaries.
                ThemeDictionaries.Clear();
                MergedDictionaries.Clear();

                MergedDictionaries.Add(new ResourceDictionary {
                    Source = new Uri("ms-appx:///Themes/" + (systemTheme ? "ThemeSystem" : "ThemeGreen") + ".xaml")
                });
            }
            catch { }
        }
Ejemplo n.º 2
0
        public void Update()
        {
            // Because of Compact, UpdateSource may be executed twice, but there is a bug in XAML and manually clear theme dictionaries here:
            // Prior to RS5, when ResourceDictionary.Source property is changed, XAML forgot to clear ThemeDictionaries.
            string deviceFamilyVersion = AnalyticsInfo.VersionInfo.DeviceFamilyVersion;
            ulong  version             = ulong.Parse(deviceFamilyVersion);
            ulong  build = (version & 0x00000000FFFF0000L) >> 16;

            if (build < 17763)
            {
                ThemeDictionaries.Clear();
            }

            MergedDictionaries.Clear();
            MergedDictionaries.Add(new ResourceDictionary {
                Source = new Uri("ms-appx:///Themes/ThemeGreen.xaml")
            });
        }
Ejemplo n.º 3
0
        public void Update(ThemeCustomInfo custom)
        {
            if (custom == null)
            {
                Update(SettingsService.Current.Appearance.RequestedTheme);
                return;
            }

            try
            {
                // Because of Compact, UpdateSource may be executed twice, but there is a bug in XAML and manually clear theme dictionaries here:
                // Prior to RS5, when ResourceDictionary.Source property is changed, XAML forgot to clear ThemeDictionaries.
                ThemeDictionaries.Clear();
                MergedDictionaries.Clear();

                MergedDictionaries.Add(new ResourceDictionary {
                    Source = new Uri("ms-appx:///Themes/ThemeGreen.xaml")
                });

                var dict = new ResourceDictionary();

                foreach (var item in custom.Values)
                {
                    if (item.Key.EndsWith("Brush"))
                    {
                        dict[item.Key] = new SolidColorBrush((Color)item.Value);
                    }
                    else if (item.Key.EndsWith("Color"))
                    {
                        dict[item.Key] = (Color)item.Value;
                    }
                }

                MergedDictionaries[0].MergedDictionaries.Clear();
                MergedDictionaries[0].MergedDictionaries.Add(dict);

                if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
                {
                    TLWindowContext.GetForCurrentView().UpdateTitleBar();
                }
            }
            catch { }
        }
Ejemplo n.º 4
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;
                }
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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("Assets/NoesisGUI/Theme/" + themeName, UriKind.Relative);

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

            return(theme);
        }
Ejemplo n.º 7
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();
         }
     }
 }
Ejemplo n.º 8
0
        private void Update(IDictionary <string, Color> values)
        {
            try
            {
                // Because of Compact, UpdateSource may be executed twice, but there is a bug in XAML and manually clear theme dictionaries here:
                // Prior to RS5, when ResourceDictionary.Source property is changed, XAML forgot to clear ThemeDictionaries.
                ThemeDictionaries.Clear();
                MergedDictionaries.Clear();

                MergedDictionaries.Add(new ResourceDictionary {
                    Source = new Uri("ms-appx:///Themes/ThemeGreen.xaml")
                });

                var dict = new ResourceDictionary();

                foreach (var item in values)
                {
                    if (item.Key.EndsWith("Brush"))
                    {
                        dict[item.Key] = new SolidColorBrush((Color)item.Value);
                    }
                    else if (item.Key.EndsWith("Color"))
                    {
                        dict[item.Key] = (Color)item.Value;
                    }
                }

                MergedDictionaries[0].MergedDictionaries.Clear();
                MergedDictionaries[0].MergedDictionaries.Add(dict);

                if (ApiInfo.HasStatusBar)
                {
                    TLWindowContext.GetForCurrentView()?.UpdateTitleBar();
                }
            }
            catch { }
        }
Ejemplo n.º 9
0
        public void Update(ElementTheme flags)
        {
            try
            {
                // Because of Compact, UpdateSource may be executed twice, but there is a bug in XAML and manually clear theme dictionaries here:
                // Prior to RS5, when ResourceDictionary.Source property is changed, XAML forgot to clear ThemeDictionaries.
                ThemeDictionaries.Clear();
                MergedDictionaries.Clear();

                if (flags == ElementTheme.Default)
                {
                    MergedDictionaries.Add(new ResourceDictionary {
                        Source = new Uri("ms-appx:///Themes/ThemeSystem.xaml")
                    });
                }
                else
                {
                    MergedDictionaries.Add(new ResourceDictionary {
                        Source = new Uri("ms-appx:///Themes/ThemeGreen.xaml")
                    });
                }
            }
            catch { }
        }