コード例 #1
0
ファイル: Theme.cs プロジェクト: hihain/UnigramMobile
        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 { }
        }
コード例 #2
0
ファイル: Theme.cs プロジェクト: sp1ke77/Unigram
        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")
            });
        }
コード例 #3
0
ファイル: Theme.cs プロジェクト: yuezhenglingluan/Unigram
        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 { }
        }
コード例 #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;
                }
            }
        }
コード例 #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);
        }
コード例 #6
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);
        }
コード例 #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();
         }
     }
 }
コード例 #8
0
ファイル: Theme.cs プロジェクト: hihain/UnigramMobile
        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 { }
        }
コード例 #9
0
ファイル: Theme.cs プロジェクト: yuezhenglingluan/Unigram
        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 { }
        }