private void InitializeCustom(string path) { var lines = File.ReadAllLines(path); var dict = new ResourceDictionary(); var flags = SettingsService.Current.Appearance.RequestedTheme == ElementTheme.Light ? TelegramTheme.Light : TelegramTheme.Dark; foreach (var line in lines) { if (line.StartsWith("name: ")) { continue; } else if (line.StartsWith("parent: ")) { flags = (TelegramTheme)int.Parse(line.Substring("parent: ".Length)); } else if (line.Equals("!") || line.Equals("#")) { continue; } else { var split = line.Split(':'); var key = split[0].Trim(); var value = split[1].Trim(); if (value.StartsWith("#") && int.TryParse(value.Substring(1), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out int hexValue)) { byte a = (byte)((hexValue & 0xff000000) >> 24); byte r = (byte)((hexValue & 0x00ff0000) >> 16); byte g = (byte)((hexValue & 0x0000ff00) >> 8); byte b = (byte)(hexValue & 0x000000ff); if (key.EndsWith("Brush")) { dict[key] = new SolidColorBrush(Color.FromArgb(a, r, g, b)); } else if (key.EndsWith("Color")) { dict[key] = Color.FromArgb(a, r, g, b); } } } } Update(); MergedDictionaries[0].MergedDictionaries.Clear(); MergedDictionaries[0].MergedDictionaries.Add(dict); if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar")) { try { TLWindowContext.GetForCurrentView().UpdateTitleBar(); } catch { } } }
private void OnActivated(object sender, WindowActivatedEventArgs e) { lock (_activeLock) { if (e.WindowActivationState != CoreWindowActivationState.Deactivated) { ActiveWindow = this; } else if (ActiveWindow == this) { ActiveWindow = null; } } }
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 { } }
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 { } }