/// <summary> /// Raises the <see cref="ThemeChanged"/> event. /// </summary> /// <param name="eventArgs"> /// <see cref="EventArgs"/> object that provides the arguments for the event. /// </param> ///// <remarks> ///// <strong>Notes to Inheritors:</strong> When overriding <see cref="OnThemeChanged"/> in a ///// derived class, be sure to call the base class's <see cref="OnThemeChanged"/> method so ///// that registered delegates receive the event. ///// </remarks> private void OnThemeChanged(EventArgs eventArgs) { ThemeChanged?.Invoke(this, eventArgs); // Broadcast message over message bus. _messageBus?.Publish(new ThemeMessage(Theme)); }
public bool SetTheme(AppTheme?theme = null) { if (IsHighContrastActive) { // TODO WTS: Set high contrast theme // You can add custom themes following the docs on https://mahapps.com/docs/themes/thememanager } else if (theme == null) { if (App.Current.Properties.Contains("Theme")) { // Read saved theme from properties var themeName = App.Current.Properties["Theme"].ToString(); theme = (AppTheme)Enum.Parse(typeof(AppTheme), themeName); } else { // Set default theme theme = AppTheme.Light; } } var currentTheme = ThemeManager.Current.DetectTheme(Application.Current); if (currentTheme == null || currentTheme.Name != theme.ToString()) { ThemeManager.Current.ChangeTheme(Application.Current, $"{theme}.Blue"); App.Current.Properties["Theme"] = theme.ToString(); ThemeChanged?.Invoke(this, EventArgs.Empty); return(true); } return(false); }
public static void UpdateCurrentTheme() { string theme; if (!EnableNightTheme) { theme = Theme; } else { var now = DateTime.Now; // start: 20:00, end: 6:00 if (NightThemeStart > NightThemeEnd) { theme = (NightThemeStart <= now.Hour || NightThemeEnd > now.Hour) ? NightTheme : Theme; } else { theme = (NightThemeStart <= now.Hour && NightThemeEnd > now.Hour) ? NightTheme : Theme; } } Console.WriteLine(theme); if (theme != CurrentTheme) { CurrentTheme = theme; ThemeChanged?.Invoke(null, EventArgs.Empty); } }
//}]} public void SetTheme(AppTheme theme) { //^^ //{[{ ThemeChanged?.Invoke(this, EventArgs.Empty); //}]} }
public SampleController() { _themeListener = new ThemeListener(); Current = this; InitializeComponent(); _themeListener.ThemeChanged += (s) => { ThemeChanged?.Invoke(this, new ThemeChangedArgs { Theme = GetCurrentTheme() }); }; // Prevent Pop in on wider screens. if (((FrameworkElement)Windows.UI.Xaml.Window.Current.Content).ActualWidth > 700) { SidePaneState = PaneState.Normal; } ThemePicker.SelectedIndex = (int)GetCurrentTheme(); ThemePicker.SelectionChanged += ThemePicker_SelectionChanged; DocumentationTextBlock.SetRenderer <SampleAppMarkdownRenderer>(); ProcessSampleEditorTime(); XamlCodeEditor.UpdateRequested += XamlCodeEditor_UpdateRequested; #if HAS_UNO CanSelectTheme = false; #endif }
public bool SetTheme(AppTheme?theme = null) { if (IsHighContrastActive) { // TODO: Set high contrast theme name } else if (theme == null) { if (App.Current.Properties.Contains("Theme")) { // Saved theme var themeName = App.Current.Properties["Theme"].ToString(); theme = (AppTheme)Enum.Parse(typeof(AppTheme), themeName); } else { // Default theme theme = AppTheme.Light; } } var currentTheme = ThemeManager.DetectTheme(Application.Current); if (currentTheme == null || currentTheme.Name != theme.ToString()) { ThemeManager.ChangeTheme(Application.Current, $"{theme}.Blue"); App.Current.Properties["Theme"] = theme.ToString(); ThemeChanged?.Invoke(this, EventArgs.Empty); return(true); } return(false); }
public void OnThemeChanged(int themeIndex) { CurrentThemeIndex = themeIndex; CurrentTheme = Utils.Themes[themeIndex]; //todo: is it nessasary? Camera.main.backgroundColor = Utils.Themes[themeIndex].BackgraoundColor; SetCursorColor(); ThemeChanged?.Invoke(null, themeIndex); }
internal static void Initialize() { Directory.CreateDirectory(ThemeProfileDirectoryPath); ReloadCandidates(); Setting.Theme.ValueChanged += _ => ThemeChanged?.Invoke(); }
public static void ChangeTheme(ITheme theme) { usingRandomTheme = theme is RandomTheme; App.Current.Resources.MergedDictionaries[1] = theme.Resource; ThemeChanged?.Invoke(new object(), new EventArgs()); Settings.Default.Theme = theme.Name; Settings.Default.Save(); }
private void OptionsViewModel_ThemeChanged(object sender) { ThemeChanged?.Invoke(sender); foreach (var tabItem in _tabItems) { ((tabItem.Content as Views.PingControl).DataContext as PingControlViewModel).SetupGraphs(); } }
private void ThemeChangeTimer_Tick(object sender, EventArgs e) { _themeChangeTimer.IsEnabled = false; RebuildTheme(); ThemeChanged?.Invoke(); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsLightTheme))); }
private void ThemeChangeTimer_Tick(object sender, EventArgs e) { _themeChangeTimer.IsEnabled = false; ThemeChanged?.Invoke(); RaisePropertyChanged(nameof(IsLightTheme)); RaisePropertyChanged(nameof(IsSystemLightTheme)); RaisePropertyChanged(nameof(UseAccentColorOnWindowBorders)); }
public void ChangeTheme(Theme theme, bool fromSettings = false) { if (fromSettings) { _settingsTheme = theme; } Theme oldTheme = _currentTheme; if (theme == Theme.System) { _currentTheme = Theme.System; if (ControlzEx.Theming.WindowsThemeHelper.IsHighContrastEnabled()) { Theme highContrastBaseType = GetHighContrastBaseType(); ChangeTheme(highContrastBaseType, false); } else { string baseColor = ControlzEx.Theming.WindowsThemeHelper.GetWindowsBaseColor(); ChangeTheme((Theme)Enum.Parse(typeof(Theme), baseColor)); } } else if (theme == Theme.HighContrastOne) { _currentTheme = Theme.HighContrastOne; ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastOneTheme); } else if (theme == Theme.HighContrastTwo) { _currentTheme = Theme.HighContrastTwo; ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastTwoTheme); } else if (theme == Theme.HighContrastWhite) { _currentTheme = Theme.HighContrastWhite; ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastWhiteTheme); } else if (theme == Theme.HighContrastBlack) { _currentTheme = Theme.HighContrastBlack; ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastBlackTheme); } else if (theme == Theme.Light) { _currentTheme = Theme.Light; ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, LightTheme); } else if (theme == Theme.Dark) { _currentTheme = Theme.Dark; ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, DarkTheme); } ThemeChanged?.Invoke(oldTheme, _currentTheme); }
int IVsBroadcastMessageEvents.OnBroadcastMessage(uint Message, IntPtr wParam, IntPtr lParam) { ThreadHelper.ThrowIfNotOnUIThread(); if (Message == 0x15) { Themes currentTheme = GetCurrentTheme(); ThemeChanged?.Invoke(currentTheme == Themes.Undefined ? Themes.Dark : currentTheme); } return(0); }
/// <summary> Chooses a new theme, different from the current one. </summary> public void ChooseNewTheme() { Theme newTheme; do { newTheme = GetRandomTheme(); } while (newTheme == CurrentTheme); CurrentTheme = newTheme; ThemeChanged?.Invoke(this, newTheme); }
public static void SetTheme(string theme) { var t = Themes.FirstOrDefault(x => x.Name.ToLowerInvariant() == theme.ToLowerInvariant()); if (t == null) { return; } CurrentTheme = t; ThemeChanged?.Invoke(); }
private void Watcher_EventArrived(object sender, EventArrivedEventArgs e) { var appTheme = ThemeHelpers.GetAppTheme(); if (appTheme != AppTheme) { AppTheme = appTheme; ThemeChanged?.Invoke(this); } }
//}]} public bool SetTheme(AppTheme?theme = null) { if (currentTheme == null || currentTheme.Name != theme.ToString()) { //^^ //{[{ ThemeChanged?.Invoke(this, EventArgs.Empty); //}]} return(true); } }
/// <summary> /// Sets the Current UI Theme. /// </summary> /// <param name="theme">Theme to set</param> public void SetCurrentTheme(ElementTheme theme) { DemoAreaGrid.RequestedTheme = theme; var args = new ThemeChangedArgs { CustomSet = true, Theme = GetCurrentTheme() }; ThemeChanged?.Invoke(this, args); }
public async Task SetTheme(SpectroTheme theme) { CurrentTheme = theme; if (Window.Current.Content is FrameworkElement frameworkElement) { frameworkElement.RequestedTheme = theme.ToElementTheme(); } _applicationSettingsService.Local.Set(RequestedThemeKey, await Json.StringifyAsync(theme)); ThemeChanged?.Invoke(this, new ThemeChangedEventArgs(CurrentTheme)); }
/// <summary> /// The callback of the Realized Event. /// </summary> /// <since_tizen> preview </since_tizen> protected override void OnRealized() { base.OnRealized(); _languageChanged = new SmartEvent(this, this.RealHandle, "language,changed"); _languageChanged.On += (s, e) => { LanguageChanged?.Invoke(this, EventArgs.Empty); }; _themeChanged = new SmartEvent(this, this.RealHandle, "theme,changed"); _themeChanged.On += (s, e) => { ThemeChanged?.Invoke(this, EventArgs.Empty); }; }
public void OnSharedPreferenceChanged(ISharedPreferences preferences, String key) { switch (key) { case "FeatureDiscoveryState": case "CurrentScheduleId": case "LastMigrationVersion": case "LastSeenUpdateVersion": break; case "UpperWeekDate": UpperWeekDate = new DateTime(preferences.GetLong("UpperWeekDate", 0)); break; // case "CheckUpdatesOnStart": // CheckUpdatesOnStart = preferences.GetBoolean("CheckUpdatesOnStart", true); // break; case "UseFabDateSelector": UseFabDateSelector = preferences.GetBoolean("UseFabDateSelector", true); break; case "UseDarkTheme": UseDarkTheme = preferences.GetBoolean("UseDarkTheme", false); ThemeChanged?.Invoke(); break; case "LessonRemindTimes": LessonRemindTimes = ParseLessonRemindTimes(preferences); LessonRemindTimesChanged?.Invoke(); break; case "DisplaySubjectEndTime": DisplaySubjectEndTime = preferences.GetBoolean("DisplaySubjectEndTime", true); break; case "UpdateSchedulesOnStart": UpdateSchedulesOnStart = preferences.GetBoolean("UpdateSchedulesOnStart", true); UpdateSchedulesOnStartChanged?.Invoke(); break; case "ReplayFeatureDiscovery": ReplayFeatureDiscovery = preferences.GetBoolean("ReplayFeatureDiscovery", false); break; } }
private void ChangeTheme(Theme theme) { Theme oldTheme = currentTheme; if (theme == currentTheme) { return; } if (theme == Theme.HighContrastOne) { ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastOneTheme); currentTheme = Theme.HighContrastOne; } else if (theme == Theme.HighContrastTwo) { ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastTwoTheme); currentTheme = Theme.HighContrastTwo; } else if (theme == Theme.HighContrastWhite) { ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastWhiteTheme); currentTheme = Theme.HighContrastWhite; } else if (theme == Theme.HighContrastBlack) { ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastBlackTheme); currentTheme = Theme.HighContrastBlack; } else if (theme == Theme.Light) { ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, LightTheme); currentTheme = Theme.Light; } else if (theme == Theme.Dark) { ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, DarkTheme); currentTheme = Theme.Dark; } else { currentTheme = Theme.None; } ThemeChanged?.Invoke(oldTheme, currentTheme); }
public void ChangeTheme(DS4Windows.AppThemeChoice themeChoice, bool fireChanged = true) { if (themeLocs.TryGetValue(themeChoice, out string loc)) { Application.Current.Resources.MergedDictionaries.Clear(); Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri(loc, uriKind: UriKind.Relative) }); if (fireChanged) { ThemeChanged?.Invoke(this, EventArgs.Empty); } } }
public void SetTheme(AppTheme theme) { if (theme == AppTheme.Default) { ThemeManager.Current.ThemeSyncMode = ThemeSyncMode.SyncAll; ThemeManager.Current.SyncTheme(); } else { ThemeManager.Current.ThemeSyncMode = ThemeSyncMode.SyncWithHighContrast; ThemeManager.Current.SyncTheme(); ThemeManager.Current.ChangeTheme(Application.Current, $"{theme}.Blue", SystemParameters.HighContrast); } App.Current.Properties["Theme"] = theme.ToString(); ThemeChanged?.Invoke(this, EventArgs.Empty); }
public static void ChangeTheme(Theme theme) { var mergedDictionaries = Application.Current.Resources.MergedDictionaries; if (mergedDictionaries != null) { mergedDictionaries.Clear(); mergedDictionaries.Add(GetDictionary(theme)); if (theme != Current) { ThemeChanged?.Invoke(Application.Current, theme); } Xamarin.Essentials.Preferences.Set(nameof(Theme), (int)theme); } }
/// <summary> /// Set our current properties and fire a change notification. /// </summary> private void UpdateProperties() { // TODO: Not sure if HighContrastScheme names are localized? if (_accessible.HighContrast && _accessible.HighContrastScheme.IndexOf("white", StringComparison.OrdinalIgnoreCase) != -1) { IsHighContrast = false; CurrentTheme = ApplicationTheme.Light; } else { // Otherwise, we just set to what's in the system as we'd expect. IsHighContrast = _accessible.HighContrast; CurrentTheme = Application.Current.RequestedTheme; } ThemeChanged?.Invoke(this); }
protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg != WmSettingChange) { return(IntPtr.Zero); } var systemParameter = Marshal.PtrToStringAuto(lParam); if (systemParameter != "ImmersiveColorSet") { return(IntPtr.Zero); } AppTheme = GetAppTheme(); WindowsTheme = GetWindowsTheme(); ThemeChanged?.Invoke(null, null !); handled = true; return(IntPtr.Zero); }
public static async Task SetTheme(ColorThemes?value, DispatcherPriority priority = DispatcherPriority.Background) { if (ThemeField == value) { return; } ThemeField = value; await Application.Current.Dispatcher.InvokeAsync(() => { if (ThemeField != value) { return; } Application.Current.Resources.BeginInit(); var curStyleRes = Resources.Where(r => r.Source != null && Regex.IsMatch(r.Source.OriginalString, StyleDictionaryPattern, RegexOptions.IgnoreCase)).FirstOrDefault(); var curThemeRes = Resources.Where(r => r.Source != null && r.Source.OriginalString.Equals(ThemeDictionaryUri, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (curThemeRes != null) { Resources.Remove(curThemeRes); } if (curStyleRes != null) { Resources.Remove(curStyleRes); } if (value == null) { return; } Resources.Add(new ResourceDictionary() { Source = new Uri($"/brightsharp;component/themes/style.{value}.xaml", UriKind.RelativeOrAbsolute) }); Resources.Add(new ResourceDictionary() { Source = new Uri(ThemeDictionaryUri, UriKind.RelativeOrAbsolute) }); Application.Current.Resources.EndInit(); ThemeChanged?.Invoke(null, EventArgs.Empty); }, priority); }
/// <summary> /// Clear and recreate resource dictionary when user changes Windows theme preferences. /// </summary> /// <param name="sender">Sender of event.</param> /// <param name="e">Event data.</param> private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e) { if (e.Category != UserPreferenceCategory.General) { return; } WindowUtilityLibrary.WindowsTheme oldTheme = CurrentTheme; WindowUtilityLibrary.WindowsTheme newTheme = GetApplicableTheme(); if (newTheme == oldTheme) { return; } Resources.MergedDictionaries.Clear(); CreateResourceDictionary(newTheme); CurrentTheme = newTheme; ThemeChanged?.Invoke(this, oldTheme); }