Ejemplo n.º 1
0
        //...

        public void Update(string theme)
        {
            BeginInit();
            MergedDictionaries.Clear();

            if (!Enum.TryParse(theme, out DefaultThemes type))
            {
                var result = new ResourceDictionary();
                result.Load(theme);

                if (result != null)
                {
                    MergedDictionaries.Add(result);
                    goto End;
                }
            }
            foreach (var i in DefaultResources)
            {
                var result = new ResourceDictionary
                {
                    Source = i[type]
                };
                MergedDictionaries.Add(result);
            }

End:
            {
                EndInit();
                this.Changed(() => Current);
            }
        }
Ejemplo n.º 2
0
        protected override void ApplyTheme(ITheme theme)
        {
            base.ApplyTheme(theme);
            if (TryGetResourceDictionaries(theme, out ResourceDictionary? light, out ResourceDictionary? dark))
            {
                switch (BaseTheme)
                {
                case Wpf.BaseTheme.Light:
                    MergedDictionaries.Add(light);
                    break;

                case Wpf.BaseTheme.Dark:
                    MergedDictionaries.Add(dark);
                    break;

                case Wpf.BaseTheme.Inherit:
                    switch (Wpf.Theme.GetSystemTheme())
                    {
                    case Wpf.BaseTheme.Dark:
                        MergedDictionaries.Add(dark);
                        break;

                    default:
                        MergedDictionaries.Add(light);
                        break;
                    }
                    break;
                }

                if (this.GetThemeManager() is IThemeManager themeManager)
                {
                    themeManager.ThemeChanged += ThemeManagerOnThemeChanged;
                }
            }
        }
Ejemplo n.º 3
0
 public object this[string index]
 {
     get
     {
         if (_innerDictionary.ContainsKey(index))
         {
             return(_innerDictionary[index]);
         }
         if (_mergedInstance != null && _mergedInstance.ContainsKey(index))
         {
             return(_mergedInstance[index]);
         }
         if (MergedDictionaries != null)
         {
             foreach (var dict in MergedDictionaries.Reverse())
             {
                 if (dict.ContainsKey(index))
                 {
                     return(dict[index]);
                 }
             }
         }
         throw new KeyNotFoundException($"The resource '{index}' is not present in the dictionary.");
     }
     set
     {
         _innerDictionary[index] = value;
         OnValueChanged(index, value);
     }
 }
Ejemplo n.º 4
0
 public virtual void LoadDictionariesFromFiles(List <string> inList)
 {
     foreach (var filePath in inList)
     {
         MergedDictionaries.Add(LoadFromFile(filePath) as EnhancedResourceDictionary);
     }
 }
Ejemplo n.º 5
0
        public Fluent()
        {
            //if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 7))
            //{
            //    this["EllipsisButtonPadding"] = new Thickness(16, 19, 16, 0);
            //    this["GlyphButtonFontSize"] = 16d;
            //    this["ChatPhotoSize"] = 30d;
            //}
            //else
            {
                this["EllipsisButtonPadding"] = new Thickness(12, 19, 12, 0);
                //this["GlyphButtonFontSize"] = 20d;
                this["ChatPhotoSize"] = 36d;

                this["GlyphButtonFontSize"]         = 16d;
                this["AppBarThemeCompactHeight"]    = 48d;
                this["NavigationViewTopPaneHeight"] = 48d;
            }

            var commonStyles = new ResourceDictionary {
                Source = new Uri("ms-appx:///Common/CommonStyles.xaml")
            };

            MergedDictionaries.Add(commonStyles);

            if (ApiInformation.IsTypePresent("Windows.UI.Xaml.Media.AcrylicBrush"))
            {
                MergedDictionaries.Add(new ResourceDictionary {
                    Source = new Uri("ms-appx:///Themes/Fluent.xaml")
                });
            }
            else
            {
                MergedDictionaries.Add(new ResourceDictionary {
                    Source = new Uri("ms-appx:///Themes/Plain.xaml")
                });
            }

            if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 7))
            {
                MergedDictionaries.Add(new Microsoft.UI.Xaml.Controls.XamlControlsResources());
            }
            else if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 6))
            {
                MergedDictionaries.Add(new Microsoft.UI.Xaml.Controls.XamlControlsResources());
            }
            else if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5))
            {
                MergedDictionaries.Add(new Microsoft.UI.Xaml.Controls.XamlControlsResources());
            }
            else
            {
                // We don't want any kind of fluent effect prior to Fall Creators Update (so fluent will affect PCs only)
                MergedDictionaries.Add(new ResourceDictionary {
                    Source = new Uri("ms-appx://Microsoft.UI.Xaml.2.4/Microsoft.UI.Xaml/Themes/rs2_themeresources.xaml")
                });
                //this["NavigationViewTopPaneHeight"] = 48d;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the XamlControlsResources class.
        /// </summary>
        public XamlControlsResources()
        {
            MergedDictionaries.Add(ControlsResources);

            if (DesignMode.DesignModeEnabled)
            {
                _ = CompactResources;
            }
        }
Ejemplo n.º 7
0
        public void Update()
        {
            MergedDictionaries.Clear();
            MergedDictionaries.Add(new ResourceDictionary {
                Source = new Uri("ms-appx:///Themes/ThemeGreen.xaml")
            });

            UpdateAcrylicBrushes();
        }
Ejemplo n.º 8
0
 public Fluent()
 {
     if (ApiInformation.IsTypePresent("Windows.UI.Xaml.Media.AcrylicBrush"))
     {
         MergedDictionaries.Add(new ResourceDictionary {
             Source = new Uri("ms-appx:///Themes/Fluent.xaml")
         });
     }
 }
Ejemplo n.º 9
0
 public Theme()
 {
     if (DesignerHelper.IsInDesignMode)
     {
         MergedDictionaries.Add(ResourceHelper.GetSkin(SkinType.Default));
         MergedDictionaries.Add(ResourceHelper.GetTheme());
     }
     else
     {
         InitResource();
     }
 }
        void OnThemeChange(ThemeChangedEventArgs e)
        {
            var uri = new Uri(baseThemeUri + "Theme" + currentTheme + ".xaml");
            ResourceDictionary ret;

            if (resourceDicts.TryGetValue(uri, out ret))
            {
                MergedDictionaries.Remove(ret);
            }
            currentTheme = Colors.DetectTheme();
            Source       = uri;
        }
Ejemplo n.º 11
0
        void ISupportInitialize.EndInit()
        {
            EndInit();

            for (int i = MergedDictionaries.Count - 1; i >= 0; i--)
            {
                if (MergedDictionaries[i] is ThemeDictionary td)
                {
                    ThemeDictionaries[td.Key] = td;
                    MergedDictionaries.RemoveAt(i);
                }
            }
        }
Ejemplo n.º 12
0
        bool TryGetMergedDictionaryValue(string key, out object value)
        {
            foreach (var dictionary in MergedDictionaries.Reverse())
            {
                if (dictionary.TryGetValue(key, out value))
                {
                    return(true);
                }
            }

            value = null;
            return(false);
        }
        public void Remove(string inResourceDictionaryName)
        {
            EnhancedResourceDictionary erdToRemove = null;

            foreach (EnhancedResourceDictionary erd in MergedDictionaries)
            {
                if (erd.Name == inResourceDictionaryName)
                {
                    erdToRemove = erd;
                }
            }
            MergedDictionaries.Remove(erdToRemove);
        }
        private void OnThemeChange(ThemeChangedEventArgs e)
        {
            var oldStyle = GetThemeUri();
            ResourceDictionary ret;

            if (SharedDictionaries.TryGetValue(oldStyle, out ret))
            {
                MergedDictionaries.Remove(ret);
            }

            SetIsDark();
            Source = oldStyle;
        }
Ejemplo n.º 15
0
 public Theme()
 {
     if (DesignerHelper.IsInDesignMode)
     {
         MergedDictionaries.Add(new ResourceDictionary()
         {
             Source = new Uri("pack://application:,,,/Quan.ControlLibrary;Component/DesignTime/DesignTimeResources.xaml")
         });
     }
     else
     {
         UpdateResource();
     }
 }
Ejemplo n.º 16
0
        protected DesignTimeThemeResourceDictionary(Theme theme)
        {
            if (PresentationCoreUtils.IsInDesignMode == false)
            {
                return;
            }

            ThemeManager.ApplicationTheme = theme;

#if SILVERLIGHT
            MergedDictionaries.Clear();
            MergedDictionaries.Add(ThemeManager.CreateThemeResourceDictionary());
#endif
        }
        private void LoadDefault(Uri value)
        {
            SetFinalSourceUri(value);

            if (SharedResourceDictionaryManager.TryGetDictionary(_source, out var dict))
            {
                MergedDictionaries.Add(dict);
            }
            else
            {
                base.Source = value;
                SharedResourceDictionaryManager.CacheDictionary(this);
            }
        }
Ejemplo n.º 18
0
 public AppStyles()
 {
     MergedDictionaries.Add(new ResourceDictionary {
         Source = new Uri("pack://application:,,,/MathCore.WPF.Styles;component/Styles/CheckBoxes/SwitcherCheckBox.xaml")
     });
     MergedDictionaries.Add(new ResourceDictionary {
         Source = new Uri("pack://application:,,,/MathCore.WPF.Styles;component/Styles/TextBoxes/TaggedTextBox.xaml")
     });
     MergedDictionaries.Add(new ResourceDictionary {
         Source = new Uri("pack://application:,,,/MathCore.WPF.Styles;component/Resources/EasingFunctions.xaml")
     });
     MergedDictionaries.Add(new ResourceDictionary {
         Source = new Uri("pack://application:,,,/MathCore.WPF.Styles;component/Resources/Colors/Brushes.xaml")
     });
 }
Ejemplo n.º 19
0
        public override void LoadDictionariesFromFiles(List <string> inList)
        {
            foreach (var filePath in inList)
            {
                // Only Globalization resource dictionaries should be added
                // Ignore other types
                var rd = LoadFromFile(filePath) as StyleResourceDictionary;
                if (rd == null)
                {
                    continue;
                }

                MergedDictionaries.Add(rd);
            }
        }
Ejemplo n.º 20
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.º 21
0
        private void ApplyCurrentPreset()
        {
            if (MergedDictionaries.Count > 0)
            {
                MergedDictionaries.Clear();
            }

            string currentPreset = PresetManager.Current.ShapePreset;

            if (currentPreset != PresetManager.DefaultPreset)
            {
                string assemblyName = GetType().Assembly.GetName().Name;
                var    source       = new Uri($"/{assemblyName};component/Presets/{currentPreset}.xaml", UriKind.Relative);
                MergedDictionaries.Add(new ResourceDictionary {
                    Source = source
                });
            }
        }
Ejemplo n.º 22
0
 public Theme()
 {
     if (DesignerHelper.IsInDesignMode)
     {
         MergedDictionaries.Add(new ResourceDictionary
         {
             Source = new Uri("pack://application:,,,/Otto.Theme;component/Themes/SkinDefault.xaml")
         });
         MergedDictionaries.Add(new ResourceDictionary
         {
             Source = new Uri("pack://application:,,,/Otto.Theme;component/Themes/Theme.xaml")
         });
     }
     else
     {
         UpdateResource();
     }
 }
Ejemplo n.º 23
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.º 24
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.º 25
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;
                }
            }
        }
        public void Remove(string inResourceDictionaryName)
        {
            EnhancedResourceDictionary erdToRemove = null;

            //enumerate through all resource dictionaries
            foreach (ResourceDictionary rd in MergedDictionaries)
            {
                //Only operate on globalized enahncedresourcedictionary types
                var erd = rd as EnhancedResourceDictionary;
                if (erd != null)
                {
                    if (erd.Name == inResourceDictionaryName)
                    {
                        erdToRemove = erd;
                    }
                }
            }
            MergedDictionaries.Remove(erdToRemove);
        }
Ejemplo n.º 27
0
        public Theme()
        {
            var main = Current == null;

            try
            {
                isolatedStore = ApplicationData.Current.LocalSettings.CreateContainer("Theme", ApplicationDataCreateDisposition.Always);
                Current ??= this;

                this.Add("MessageFontSize", GetValueOrDefault("MessageFontSize", 14d));

                var emojiSet = SettingsService.Current.Appearance.EmojiSet;
                switch (emojiSet.Id)
                {
                case "microsoft":
                    this.Add("EmojiThemeFontFamily", new FontFamily($"XamlAutoFontFamily"));
                    break;

                case "apple":
                    this.Add("EmojiThemeFontFamily", new FontFamily($"ms-appx:///Assets/Emoji/{emojiSet.Id}.ttf#Segoe UI Emoji"));
                    break;

                default:
                    this.Add("EmojiThemeFontFamily", new FontFamily($"ms-appdata:///local/emoji/{emojiSet.Id}.{emojiSet.Version}.ttf#Segoe UI Emoji"));
                    break;
                }

                this.Add("ThreadStackLayout", new StackLayout());
            }
            catch { }

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

            if (main)
            {
                UpdateAcrylicBrushes();
                Initialize();
            }
        }
Ejemplo n.º 28
0
        public override void LoadDictionariesFromFiles(List <string> inList)
        {
            foreach (var filePath in inList)
            {
                // Only Globalization resource dictionaries should be added
                // Ignore other types
                var globalizationResourceDictionary = LoadFromFile(filePath) as GlobalizationResourceDictionary;
                if (globalizationResourceDictionary == null)
                {
                    continue;
                }

                MergedDictionaries.Add(globalizationResourceDictionary);

                if (globalizationResourceDictionary.LinkedStyle == null)
                {
                    continue;
                }

                var styleFile = globalizationResourceDictionary.LinkedStyle + ".xaml";
                if (globalizationResourceDictionary.Source != null)
                {
                    var path = Path.Combine(Path.GetDirectoryName(globalizationResourceDictionary.Source), styleFile);
                    // Todo: Check for file and if not there, look in the Styles dir

                    var tempStyleDict = LoadFromFile(path, false);
                    if (tempStyleDict != null)
                    {
                        MergedDictionaries.Add(tempStyleDict);
                    }
                    return;
                }

                var styleDict = LoadFromFile(styleFile, false);
                if (styleDict != null)
                {
                    MergedDictionaries.Add(styleDict);
                }
            }
        }
Ejemplo n.º 29
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.º 30
0
        ///<summary>Creates a new <see cref="VsThemeDictionary"/>, initializing the <see cref="VsServiceProvider"/> if it has not been initialized.</summary>
        public VsThemeDictionary()
        {
            if (ServiceProvider.GlobalProvider.GetService(typeof(SVsFrameworkMultiTargeting)) != null)
            {
                return;                 // Do nothing when hosted in VS
            }
            VsServiceProvider.Initialize();
            service = Activator.CreateInstance(WindowManagement.GetType("Microsoft.VisualStudio.Platform.WindowManagement.ColorThemeService"));

            // Add an empty dictionary for the loader to replace.
            MergedDictionaries.Add(new ResourceDictionary());
            ThemeIndex = 0;

            typeof(EnvironmentRenderCapabilities)
            .GetProperty("VisualEffectsAllowed")
            .SetValue(EnvironmentRenderCapabilities.Current, 1 | 2);

            Themes = Enumerable.Range(0, (int)service.Themes.Count)
                     .Select(i => new ColorTheme(i, service.Themes[i]))
                     .ToList()
                     .AsReadOnly();
        }