public void SetTheme(ResourceDictionary dictionary) { var dictionaries = Application.Current.Resources.MergedDictionaries; if (dictionary != null) { dictionaries.Add(dictionary); } if (CurrentThemeDictionary != null) { dictionaries.Remove(CurrentThemeDictionary); } CurrentThemeDictionary = dictionary; ThemeChange?.Invoke(this, EventArgs.Empty); }
private void ButtonTapped(object sender, TappedRoutedEventArgs e) { if (Window.Current.Content is FrameworkElement frameworkElement) { if (frameworkElement.RequestedTheme == ElementTheme.Dark) { frameworkElement.RequestedTheme = ElementTheme.Light; ToLight.Begin(); //Storyboard isLight = true; //标题栏颜色 ThemeChange?.Invoke(this, ElementTheme.Light); //Delegate } else { frameworkElement.RequestedTheme = ElementTheme.Dark; ToNight.Begin(); //Storyboard isLight = false; //标题栏颜色 ThemeChange?.Invoke(this, ElementTheme.Dark); //Delegate } } }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { if (App.localSettings.Values.ContainsKey("isLight") == false) //判断本地设置有没有这个字典 { App.localSettings.Values["isLight"] = true; //资源容器 } if ((bool)App.localSettings.Values["isLight"] == false) //判断是不是明主题 { App.Model.Theme = ElementTheme.Dark; ToNight.Begin(); Night(); } else { App.Model.Theme = ElementTheme.Light; ToLight.Begin(); Light(); } ThemeChange?.Invoke(this, App.Model.Theme); }
private void Button_Tapped(object sender, TappedRoutedEventArgs e) { if (App.Model.Theme == ElementTheme.Light) { App.localSettings.Values["isLight"] = false;//资源容器 ToNight.Begin(); Night(); App.Model.Theme = this.RequestedTheme = ElementTheme.Dark; } else { App.localSettings.Values["isLight"] = true;//资源容器 ToLight.Begin(); Light(); App.Model.Theme = this.RequestedTheme = ElementTheme.Light; } ThemeChange?.Invoke(this, App.Model.Theme); App.Model.Refresh++;//画布刷新 }