//... 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); } }
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; } } }
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); } }
public virtual void LoadDictionariesFromFiles(List <string> inList) { foreach (var filePath in inList) { MergedDictionaries.Add(LoadFromFile(filePath) as EnhancedResourceDictionary); } }
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; } }
/// <summary> /// Initializes a new instance of the XamlControlsResources class. /// </summary> public XamlControlsResources() { MergedDictionaries.Add(ControlsResources); if (DesignMode.DesignModeEnabled) { _ = CompactResources; } }
public void Update() { MergedDictionaries.Clear(); MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("ms-appx:///Themes/ThemeGreen.xaml") }); UpdateAcrylicBrushes(); }
public Fluent() { if (ApiInformation.IsTypePresent("Windows.UI.Xaml.Media.AcrylicBrush")) { MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("ms-appx:///Themes/Fluent.xaml") }); } }
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; }
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); } } }
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; }
public Theme() { if (DesignerHelper.IsInDesignMode) { MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri("pack://application:,,,/Quan.ControlLibrary;Component/DesignTime/DesignTimeResources.xaml") }); } else { UpdateResource(); } }
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); } }
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") }); }
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); } }
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 { } }
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 }); } }
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(); } }
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") }); }
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 { } }
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); }
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(); } }
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); } } }
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(); } } }
///<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(); }