private static void ConfigureSnackBar() { UISettings uiSettings = new UISettings(); SnackBarAppearance.Opacity = 1; SnackBarAppearance.Transition = new PopupThemeTransition(); //check for acrylic support if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.Xaml.Media.XamlCompositionBrushBase") && Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.Xaml.Media.AcrylicBrush")) { //Add acrylic. Windows.UI.Xaml.Media.AcrylicBrush myBrush = new Windows.UI.Xaml.Media.AcrylicBrush(); myBrush.BackgroundSource = Windows.UI.Xaml.Media.AcrylicBackgroundSource.Backdrop; myBrush.TintColor = uiSettings.GetColorValue(UIColorType.AccentDark2); myBrush.FallbackColor = uiSettings.GetColorValue(UIColorType.AccentDark2); myBrush.Opacity = 0.6; myBrush.TintOpacity = 0.5; SnackBarAppearance.BackgroundBrush = myBrush; } else { //fallback to a solid color. SnackBarAppearance.BackgroundBrush = new SolidColorBrush(uiSettings.GetColorValue(UIColorType.Accent)); } }
private void OnSetColorToSystemColorExecute() { UISettings uiSettings = new UISettings(); AppSettings.Default.BackgroundColor = uiSettings.GetColorValue(UIColorType.Accent).ToString(); AppSettings.Default.ForegroundColor = uiSettings.GetColorValue(UIColorType.Background).ToString(); }
public MainPage() { Logger.Log("MainPage:Constructor: called"); //SLOW: Inititalizing components takes 2020 milliseconds this.InitializeComponent(); Logger.LogBlock = uiLog; Logger.Log("MainPage:Constructor: called and components initialized"); Nav.AddNavigateTo(Navigator.NavigateControlId.ChapterDisplay, uiChapterControl); Nav.AddNavigateTo(Navigator.NavigateControlId.MainReader, uiReaderControl); Nav.AddNavigateTo(Navigator.NavigateControlId.ProjectRome, RomeActivity); // Will be added automatically as needed: Nav.AddSelectTo(Navigator.NavigateControlId.WebSearchDisplay, uiWebSearchControl); // SimpleBookHandler is just for notes, not really "books" per se. Nav.AddSimpleBookHandler(Navigator.NavigateControlId.MainPage, this); Nav.AddSimpleBookHandler(Navigator.NavigateControlId.NoteListDisplay, uiNoteList); Nav.AddSimpleBookHandler(Navigator.NavigateControlId.BookSearchDisplay, uiBookSearchControl); Nav.AddSimpleBookHandler(Navigator.NavigateControlId.ProjectRome, RomeActivity); Nav.AddSetAppColor(Navigator.NavigateControlId.MainPage, this); Nav.AddSetAppColor(Navigator.NavigateControlId.MainReader, uiReaderControl); Nav.MainBookHandler = uiReaderControl; uiReaderControl.SetChapters = uiChapterControl; uiReaderControl.SetImages = uiImageControl; uiReaderControl.SetImages2 = RomeActivity; uiReaderControl.SetImages3 = this; uiNoteList.ParentCommandBar = uiSecondDisplayCommandBar; uiWebSearchControl.ParentCommandBar = uiSecondDisplayCommandBar; uiBookSearchControl.ParentCommandBar = uiSecondDisplayCommandBar; // Customization has to happen after the MainBookHandler is set up. var userCustomization = (App.Current as App).Customization; userCustomization.Initialize(); this.Loaded += MainPage_Loaded; // Update the title bar. Reset back to the original default colors. // Need to do this because I horked everything :-) #if NEVER_EVER_DEFINED if (false) { var uis = new UISettings(); var titleBar = ApplicationView.GetForCurrentView().TitleBar; var dict = App.Current.Resources; titleBar.BackgroundColor = uis.GetColorValue(UIColorType.Background); titleBar.ForegroundColor = uis.GetColorValue(UIColorType.Foreground); titleBar.ButtonBackgroundColor = uis.GetColorValue(UIColorType.Background); titleBar.ButtonForegroundColor = (Color)Resources["SystemAccentColor"]; //uis.GetColorValue(UIColorType.Foreground); } #endif // COLORTHEME: no colors // // // this.ActualThemeChanged += MainPage_ActualThemeChanged; // // // UISettings = new UISettings(); // // // UISettings.ColorValuesChanged += UISettings_ColorValuesChanged; Logger.Log("MainPage:Constructor: returning"); }
private void ListenToSystemColorChanges() { var uiSettings = new UISettings(); _systemBackground = uiSettings.GetColorValue(UIColorType.Background).ToColor(); _systemAccent = uiSettings.GetColorValue(UIColorType.Accent).ToColor(); uiSettings.ColorValuesChanged += (sender, args) => { #if DEBUG //for (int i = 0; i <= 8; i++) //{ // var colorType = (UIColorType)i; // Debug.WriteLine(colorType + " = " + sender.GetColorValue(colorType)); //} #endif var background = sender.GetColorValue(UIColorType.Background).ToColor(); if (_systemBackground != background) { _systemBackground = background; BackgroundColorChanged?.Invoke(null, EventArgs.Empty); } var accent = sender.GetColorValue(UIColorType.Accent).ToColor(); if (_systemAccent != accent) { _systemAccent = accent; AccentColorChanged?.Invoke(null, EventArgs.Empty); } }; _uiSettings = uiSettings; }
private void UpdateColors() { if (_settings == null) { return; } bool active = _window != null && _window.ActivationMode == CoreWindowActivationMode.ActivatedInForeground; TemplateSettings.BackgroundColor = Colors.Transparent;// _settings.GetColorValue(active ? UIColorType.Accent : UIColorType.AccentDark1); var darkAccent = _settings.GetColorValue(UIColorType.AccentDark1); var btnHoverColor = _settings.GetColorValue(UIColorType.AccentLight1); var foreground = ResourceHelper.GetEffectiveTheme() == ElementTheme.Dark ? Colors.White : Colors.Black; ApplyColorToTitleBar( Colors.Transparent, foreground, darkAccent, Colors.Gray); ApplyColorToTitleButton( Colors.Transparent, foreground, btnHoverColor, foreground, Colors.Transparent, foreground, Colors.Transparent, Colors.Gray); }
private byte[] GenerateThemeContent(LoadDataArgs args) { var accentColor = _uiSettings.GetColorValue(UIColorType.Accent); var backgroundColor = _uiSettings.GetColorValue(UIColorType.Background); var foregroundColor = _uiSettings.GetColorValue(UIColorType.Foreground); var accentLight2Color = _uiSettings.GetColorValue(UIColorType.AccentLight2); SciterColor sciterAccentColor = SciterColor.Create(accentColor.R, accentColor.G, accentColor.B, accentColor.A); SciterColor sciterBackgroundColor = SciterColor.Create(backgroundColor.R, backgroundColor.G, backgroundColor.B, backgroundColor.A); SciterColor sciterForeground = SciterColor.Create(foregroundColor.R, foregroundColor.G, foregroundColor.B, foregroundColor.A); SciterColor sciterAccentLight2 = SciterColor.Create(accentLight2Color.R, accentLight2Color.G, accentLight2Color.B, accentLight2Color.A); var themeCss = @$ " html:theme(system) {{ var(accent-color): {sciterAccentColor.ToShortHtmlColor()}; var(main-bg-color): {sciterBackgroundColor.ToShortHtmlColor()}; var(main-color): {sciterForeground.ToShortHtmlColor()}; var(card-bg-color): morph(color(main-color), opacity: 7.5%); var(card-bd-color): morph(color(main-color), opacity: 50%); var(card-bd-width): 2dip; var(header-bg-color): color(accent-color); var(toolbar-bg-color): morph(color(main-color), opacity: 10%); var(menu-main-color): #D0D2D6; var(menu-color): morph(rgb(255,255,255), opacity: 85%); var(menu-bg-color): morph(#262930, darken: 4%); var(menu-h-color): morph(color(menu-color), lighten: 10%); var(menu-h-bg-color): morph(color(accent-color), opacity: 75%); }} card:theme(system) {{ border: transparent; box-shadow: none; }} card:hover:theme(system) {{ box-shadow: none; }} cardheader:theme(system) > div:nth-child(2) {{ color: {sciterAccentLight2.ToShortHtmlColor()}; opacity: 1; }} "; return(System.Text.Encoding.UTF8.GetBytes(themeCss)); } } }
private void UpdateFallbackBrush() { if (_target.TryGetTarget(out var target)) { if (_micaController.Value == null) { // When not using mica, use the theme and high contrast states to determine the fallback color. ElementTheme GetTheme() { // See other IsRS3OrHigher usage for comment explaining why the version check and QI. if (SharedHelpers.IsRS3OrHigher()) { if (target is FrameworkElement targetTheme) { return(targetTheme.ActualTheme); } } var value = _uiSettings.GetColorValue(UIColorType.Background); if (value.B == 0) { return(ElementTheme.Dark); } return(ElementTheme.Light); } var theme = GetTheme(); Color GetColor() { if (_isHighContrast) { return(_uiSettings.GetColorValue(UIColorType.Background)); } if (theme == ElementTheme.Dark) { return(MicaController.DarkThemeColor); } else { return(MicaController.LightThemeColor); } } var color = GetColor(); target.Background = new SolidColorBrush(color); } else { // When Mica is involved, use transparent for the background (this is so that the hit testing // behavior is consistent with/without the material). target.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)); } } }
private static bool IsDarkModeWin(UISettings settings) { var foreground = settings.GetColorValue(UIColorType.Foreground); var background = settings.GetColorValue(UIColorType.Background); Debug.WriteLine($"Foreground {foreground} Background {background}"); return(background.ToString() == "#FF000000"); }
public void GetFocus() { FocusedBar.Background = new SolidColorBrush(UI.GetColorValue(UIColorType.Accent)); focused = true; PlayIcon.Glyph = "\uE769"; Foreground = new SolidColorBrush(UI.GetColorValue(UIColorType.Accent)); PlayIcon.Visibility = Visibility.Visible; }
/// <summary> /// Checks whether Windows has light or dark color theme /// </summary> /// <returns></returns> private static AppTheme GetWindowsTheme() { var color = UiSettings.GetColorValue(UIColorType.Background); if (color.ToString(CultureInfo.InvariantCulture).Equals("#FF000000", StringComparison.InvariantCultureIgnoreCase)) { return(AppTheme.Dark); } return(AppTheme.Light); }
public CssManager() { var uiSettings = new UISettings(); var color = uiSettings.GetColorValue(UIColorType.Accent); var color1 = uiSettings.GetColorValue(UIColorType.AccentDark2); var color2 = uiSettings.GetColorValue(UIColorType.AccentLight2); AccentColour = "#" + color.ToString().Substring(3); AccentColourLight = "#" + color2.ToString().Substring(3); AccentColourDark = "#" + color1.ToString().Substring(3); }
private void ColorValuesChanged(UISettings sender, object args) { var accentColor = sender.GetColorValue(UIColorType.Accent); //OR //Color accentColor = (Color)Resources["SystemAccentColor"]; var backgroundColor = sender.GetColorValue(UIColorType.Background); var isDarkMode = backgroundColor == Colors.Black; ChangeLog.Insert(0, new ChangeLogItem(accentColor, isDarkMode, DateTimeOffset.Now)); //Example - update title bar UpdateTitleBar(accentColor); }
private void ListenToSystemColorChanges() { _uiSettings = new UISettings(); _uiSettings.ColorValuesChanged += OnColorValuesChanged; if (PackagedAppHelper.IsPackagedApp) { SystemEvents.UserPreferenceChanged += OnUserPreferenceChanged; } _systemBackground = _uiSettings.GetColorValue(UIColorType.Background).ToColor(); _systemAccent = _uiSettings.GetColorValue(UIColorType.Accent).ToColor(); UpdateSystemAppTheme(); }
public MainViewModel() { UISettings settings = new UISettings(); var foreground = settings.GetColorValue(UIColorType.Foreground); var background = settings.GetColorValue(UIColorType.Background); Color myforeColor = Color.FromArgb(foreground.A, foreground.R, foreground.G, foreground.B); ForeBrush = new SolidColorBrush(myforeColor); Color mybackColor = Color.FromArgb(background.A, background.R, background.G, background.B); BackBrush = new SolidColorBrush(mybackColor); Title = "Welcome to WPF"; }
private void ToggleSwitch_Toggled(object sender, RoutedEventArgs e) { ToggleSwitch toggle = sender as ToggleSwitch; ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; UISettings uiSettings = new UISettings(); switch (toggle.Tag as string) { case "0": case "1": case "3": localSettings.Values[toggle.Name] = toggle.IsOn; break; case "2": localSettings.Values[toggle.Name] = toggle.IsOn; CheckTheme(); break; //case "4": // localSettings.Values[toggle.Name] = toggle.IsOn; // if (toggle.IsOn) Application.Current.Resources["SystemAccentColor"] = uiSettings.GetColorValue(UIColorType.Accent); // else Application.Current.Resources["SystemAccentColor"] = Color.FromArgb(255, 76, 175, 80); // Window.Current.Content.UpdateLayout(); // CheckTheme(); // break; case "5": localSettings.Values[toggle.Name] = toggle.IsOn; localSettings.Values["IsDarkMode"] = uiSettings.GetColorValue(UIColorType.Background).Equals(Colors.Black) ? true : false; CheckTheme(); IsDarkMode.IsOn = Convert.ToBoolean(localSettings.Values["IsDarkMode"]); IsDarkMode.Visibility = toggle.IsOn ? Visibility.Collapsed : Visibility.Visible; break; } }
private void UpdateStatusBar() { // === 1. Determine the current theme from the background value, // which is calculated from the theme and can only be black or white. var backgroundColor = _uiSettings.GetColorValue(UIColorType.Background); var isDarkMode = backgroundColor == Windows.UI.Colors.Black; #if __IOS__ || __ANDROID__ // === 2. Set the foreground color. // note: The foreground color can only be set to a "dark/light" value. See uno remarks on StatusBar.ForegroundColor. // note: For ios in dark mode, setting this value will have no effect. var foreground = isDarkMode ? Windows.UI.Colors.White : Windows.UI.Colors.Black; Windows.UI.ViewManagement.StatusBar.GetForCurrentView().ForegroundColor = foreground; // === 3. Set the background color. var background = isDarkMode ? Windows.UI.Colors.MidnightBlue : Windows.UI.Colors.SkyBlue; #if __ANDROID__ // On Android, this is done by calling Window.SetStatusBarColor. if (Uno.UI.ContextHelper.Current is Android.App.Activity activity) { activity.Window.SetStatusBarColor(background); } #endif // On iOS, this is done via the native CommandBar which goes under the status bar. // For android, we will also update the CommandBar just for consistency. if (MainPage.Instance.GetCommandBar() is CommandBar commandBar) { commandBar.Foreground = new SolidColorBrush(foreground); // controls the color for the "MainPage" page title commandBar.Background = new SolidColorBrush(background); } #endif }
private static void SetBackgroundTheme(UISettings o, object _) { if (Get <bool>(IsBackgroundColorFollowSystem)) { Set(IsDarkMode, o.GetColorValue(UIColorType.Background) == Windows.UI.Colors.Black); } }
private Color Win10ColorToMediaColor(UISettings uiSettings, UIColorType colorType) { Windows.UI.Color win10Color = uiSettings.GetColorValue(colorType); Color mediaColor = Color.FromArgb(win10Color.A, win10Color.R, win10Color.G, win10Color.B); return(mediaColor); }
private void DetectApplicationTheme() { if (localSettings.Values["theme"] != null) { if (localSettings.Values["theme"].ToString() == "Light") { ThemeValue = ThemeStyle.Light; App.Current.RequestedTheme = ApplicationTheme.Light; return; } else if (localSettings.Values["theme"].ToString() == "Dark") { ThemeValue = ThemeStyle.Dark; App.Current.RequestedTheme = ApplicationTheme.Dark; return; } } var uiSettings = new UISettings(); var color = uiSettings.GetColorValue(UIColorType.Background); if (color == Colors.White) { ThemeValue = ThemeStyle.System; App.Current.RequestedTheme = ApplicationTheme.Light; } else { ThemeValue = ThemeStyle.System; App.Current.RequestedTheme = ApplicationTheme.Dark; } }
public void UpdateColorTheme() { if (new AccessibilitySettings().HighContrast) { return; } ElementTheme theme = ExportProvider.GetExport <ISettingsProvider>().GetSetting(SettingsDefinitions.Theme); if (theme == ElementTheme.Default) { // Detects the Windows's theme var uiSettings = new UISettings(); var color = uiSettings.GetColorValue(Windows.UI.ViewManagement.UIColorType.Background); if (color == Colors.Black) { theme = ElementTheme.Dark; } else { theme = ElementTheme.Light; } } SetColorTheme(theme); }
private void UpdateTitleBarButtonForegroundColors() { bool IsDarkThemeCurrently() { if (this.ViewModel == null) { return(false); // Whatever, doesnt really matter because we will update again once we have a ViewModel } if (this.ViewModel.Theme == ElementTheme.Default) { var settings = new UISettings(); return(settings.GetColorValue(UIColorType.Background) == Colors.Black); } return(this.ViewModel.Theme == ElementTheme.Dark); } Execute.OnUIThread(() => { Color color = IsDarkThemeCurrently() ? Colors.White : Colors.Black; ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar; titleBar.ButtonForegroundColor = color; }); }
private void InitializeLineColor() { var defaultTheme = new UISettings(); var uiThemeColor = defaultTheme.GetColorValue(UIColorType.Background); SetLineColor(uiThemeColor); }
private void ConfigureStatusBar() { // Listen for the system theme changes. _uiSettings = new UISettings(); _uiSettings.ColorValuesChanged += (s, e) => { #if __ANDROID__ var backgroundColor = _uiSettings.GetColorValue(UIColorType.Background); var isDarkMode = backgroundColor == Windows.UI.Colors.Black; // Prevent deadlock as setting StatusBar.ForegroundColor will also trigger this event. if (_wasDarkMode == isDarkMode) { return; } _wasDarkMode = isDarkMode; #endif UpdateStatusBar(); }; #if __IOS__ // Force an update when the app is launched. UpdateStatusBar(); #endif }
private async void UIS_ColorValuesChanged(UISettings sender, object args) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { ProgressBarForeground = new SolidColorBrush(sender.GetColorValue(UIColorType.Accent)); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ProgressBarForeground))); }); }
/// <summary> /// Get the ApplicationTheme of the device/system /// </summary> public static ApplicationTheme GetSystemApplicationTheme() { var settings = new UISettings(); var systemBackground = settings.GetColorValue(UIColorType.Background); var black = Color.FromArgb(255, 0, 0, 0); return(systemBackground == black ? ApplicationTheme.Dark : ApplicationTheme.Light); }
public static bool IsAccentColorDark() { var uiSettings = new UISettings(); var c = uiSettings.GetColorValue(UIColorType.Accent); var isDark = (5 * c.G + 2 * c.R + c.B) <= 8 * 128; return(isDark); }
private void UpdateColorValues() { var background = _uiSettings.GetColorValue(UIColorType.Background).ToColor(); if (_systemBackground != background) { _systemBackground = background; UpdateSystemAppTheme(); SystemThemeChanged?.Invoke(null, EventArgs.Empty); } var accent = _uiSettings.GetColorValue(UIColorType.Accent).ToColor(); if (_systemAccent != accent) { _systemAccent = accent; SystemAccentColorChanged?.Invoke(null, EventArgs.Empty); } }
public PlatformColorService() { _uiSettings.ColorValuesChanged += _uiSettings_ColorValuesChanged; // Initial values var accentColor = _uiSettings.GetColorValue(UIColorType.Accent); _platformAccentColor = new BehaviorSubject <Color>(accentColor.ToXamarinColor()); var foregroundColor = _uiSettings.GetColorValue(UIColorType.Foreground); _platformForegroundColor = new BehaviorSubject <Color>(foregroundColor.ToXamarinColor()); var backgroundColor = _uiSettings.GetColorValue(UIColorType.Background); _platformBackgroundColor = new BehaviorSubject <Color>(backgroundColor.ToXamarinColor()); }
private async void ColorValuesChanged(UISettings sender, object args) { Color backgroundColor = sender.GetColorValue(UIColorType.Background); bool isDarkMode = backgroundColor == Colors.Black; await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { SetTextBlockColors(); }); }
public static bool IsDarkTheme() { var selectedTheme = SettingsRepository <GeneralSettings> .GetInstance(settingsUtils).SettingsConfig.Theme.ToUpper(CultureInfo.InvariantCulture); var defaultTheme = new UISettings(); var uiTheme = defaultTheme.GetColorValue(UIColorType.Background).ToString(System.Globalization.CultureInfo.InvariantCulture); return(selectedTheme == "DARK" || (selectedTheme == "SYSTEM" && uiTheme == "#FF000000")); }