Fix settings navigation and fix flicker on personalizaton nav.

This commit is contained in:
Burak Kaan Köse
2025-10-04 14:44:51 +02:00
parent 2f5d4dad9a
commit a00ff3df46
4 changed files with 55 additions and 31 deletions
@@ -1,6 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
@@ -127,14 +126,6 @@ public partial class PersonalizationPageViewModel : CoreBaseViewModel
[ObservableProperty] [ObservableProperty]
public partial BackdropTypeWrapper SelectedBackdropType { get; set; } public partial BackdropTypeWrapper SelectedBackdropType { get; set; }
partial void OnSelectedBackdropTypeChanged(BackdropTypeWrapper value)
{
if (!isPropChangeDisabled && value != null)
{
_newThemeService.CurrentBackdropType = value.BackdropType;
}
}
#endregion #endregion
[RelayCommand] [RelayCommand]
@@ -218,12 +209,9 @@ public partial class PersonalizationPageViewModel : CoreBaseViewModel
var currentThemeId = _newThemeService.CurrentApplicationThemeId; var currentThemeId = _newThemeService.CurrentApplicationThemeId;
SelectedAppTheme = currentThemeId.HasValue ? AppThemes.Find(a => a.Id == currentThemeId.Value) : null; SelectedAppTheme = currentThemeId.HasValue ? AppThemes.Find(a => a.Id == currentThemeId.Value) : null;
// Set the current backdrop, default to Mica if theme selected, None if custom theme // Set the current backdrop from service - backdrop should be independent of theme selection
var targetBackdropType = SelectedAppTheme != null && SelectedAppTheme.AppThemeType != AppThemeType.Custom var currentBackdropType = _newThemeService.CurrentBackdropType;
? _newThemeService.CurrentBackdropType SelectedBackdropType = AvailableBackdropTypes?.FirstOrDefault(x => x.BackdropType == currentBackdropType);
: WindowBackdropType.None;
SelectedBackdropType = AvailableBackdropTypes?.FirstOrDefault(x => x.BackdropType == targetBackdropType);
} }
public override async void OnNavigatedTo(NavigationMode mode, object parameters) public override async void OnNavigatedTo(NavigationMode mode, object parameters)
@@ -310,14 +298,11 @@ public partial class PersonalizationPageViewModel : CoreBaseViewModel
// Set the theme ID, can be null if no theme is selected // Set the theme ID, can be null if no theme is selected
_newThemeService.CurrentApplicationThemeId = SelectedAppTheme?.Id; _newThemeService.CurrentApplicationThemeId = SelectedAppTheme?.Id;
// When a custom/predefined theme is selected, set backdrop to None // Theme selection should not affect backdrop - they are independent settings
// When no theme is selected (system theme), keep current backdrop }
if (SelectedAppTheme != null) else if (e.PropertyName == nameof(SelectedBackdropType) && SelectedBackdropType != null)
{ {
isPropChangeDisabled = true; _newThemeService.CurrentBackdropType = SelectedBackdropType.BackdropType;
SelectedBackdropType = AvailableBackdropTypes?.FirstOrDefault(x => x.BackdropType == WindowBackdropType.None);
isPropChangeDisabled = false;
}
} }
else else
{ {
+20 -8
View File
@@ -146,6 +146,9 @@ public class NewThemeService : INewThemeService
get { return currentBackdropType; } get { return currentBackdropType; }
set set
{ {
// Only update if the backdrop type has actually changed
if (currentBackdropType == value) return;
currentBackdropType = value; currentBackdropType = value;
_configurationService.Set(WindowBackdropTypeKey, (int)value); _configurationService.Set(WindowBackdropTypeKey, (int)value);
@@ -222,11 +225,14 @@ public class NewThemeService : INewThemeService
_ => new MicaBackdrop() { Kind = Microsoft.UI.Composition.SystemBackdrops.MicaKind.Base } _ => new MicaBackdrop() { Kind = Microsoft.UI.Composition.SystemBackdrops.MicaKind.Base }
}; };
windowEx.SystemBackdrop = backdrop; if (windowEx.SystemBackdrop != backdrop)
{
windowEx.SystemBackdrop = backdrop;
BackdropChanged?.Invoke(this, backdropType); BackdropChanged?.Invoke(this, backdropType);
Debug.WriteLine($"Applied backdrop: {backdropType}"); Debug.WriteLine($"Applied backdrop: {backdropType}");
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -284,11 +290,9 @@ public class NewThemeService : INewThemeService
bool isDarkTheme = _underlyingThemeService.IsUnderlyingThemeDark(); bool isDarkTheme = _underlyingThemeService.IsUnderlyingThemeDark();
// Set button colors based on theme // Set button colors based on theme
// Background is always transparent for all buttons // Normal and inactive backgrounds are transparent, but hover/pressed have subtle backgrounds
titleBar.ButtonBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent titleBar.ButtonBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent
titleBar.ButtonInactiveBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent titleBar.ButtonInactiveBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent
titleBar.ButtonPressedBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent
if (isDarkTheme) if (isDarkTheme)
{ {
@@ -296,7 +300,11 @@ public class NewThemeService : INewThemeService
titleBar.ButtonForegroundColor = Color.FromArgb(255, 255, 255, 255); // White titleBar.ButtonForegroundColor = Color.FromArgb(255, 255, 255, 255); // White
titleBar.ButtonInactiveForegroundColor = Color.FromArgb(128, 255, 255, 255); // Semi-transparent white titleBar.ButtonInactiveForegroundColor = Color.FromArgb(128, 255, 255, 255); // Semi-transparent white
titleBar.ButtonHoverForegroundColor = Color.FromArgb(255, 255, 255, 255); // White titleBar.ButtonHoverForegroundColor = Color.FromArgb(255, 255, 255, 255); // White
titleBar.ButtonPressedForegroundColor = Color.FromArgb(200, 255, 255, 255); // Slightly dimmed white titleBar.ButtonPressedForegroundColor = Color.FromArgb(255, 255, 255, 255); // White
// Subtle hover and pressed backgrounds for dark theme
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(20, 255, 255, 255); // Very subtle white overlay
titleBar.ButtonPressedBackgroundColor = Color.FromArgb(40, 255, 255, 255); // Slightly more visible white overlay
} }
else else
{ {
@@ -304,7 +312,11 @@ public class NewThemeService : INewThemeService
titleBar.ButtonForegroundColor = Color.FromArgb(255, 0, 0, 0); // Black titleBar.ButtonForegroundColor = Color.FromArgb(255, 0, 0, 0); // Black
titleBar.ButtonInactiveForegroundColor = Color.FromArgb(128, 0, 0, 0); // Semi-transparent black titleBar.ButtonInactiveForegroundColor = Color.FromArgb(128, 0, 0, 0); // Semi-transparent black
titleBar.ButtonHoverForegroundColor = Color.FromArgb(255, 0, 0, 0); // Black titleBar.ButtonHoverForegroundColor = Color.FromArgb(255, 0, 0, 0); // Black
titleBar.ButtonPressedForegroundColor = Color.FromArgb(200, 0, 0, 0); // Slightly dimmed black titleBar.ButtonPressedForegroundColor = Color.FromArgb(255, 0, 0, 0); // Black
// Subtle hover and pressed backgrounds for light theme
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(20, 0, 0, 0); // Very subtle black overlay
titleBar.ButtonPressedBackgroundColor = Color.FromArgb(40, 0, 0, 0); // Slightly more visible black overlay
} }
Debug.WriteLine($"Updated title bar button colors for {(isDarkTheme ? "dark" : "light")} theme"); Debug.WriteLine($"Updated title bar button colors for {(isDarkTheme ? "dark" : "light")} theme");
@@ -32,6 +32,12 @@ public sealed partial class ManageAccountsPage : ManageAccountsPageAbstract,
{ {
base.OnNavigatedTo(e); base.OnNavigatedTo(e);
// Re-register message handlers after base.OnNavigatedTo unregisters all handlers
WeakReferenceMessenger.Default.Register<BreadcrumbNavigationRequested>(this);
WeakReferenceMessenger.Default.Register<BackBreadcrumNavigationRequested>(this);
WeakReferenceMessenger.Default.Register<MergedInboxRenamed>(this);
WeakReferenceMessenger.Default.Register<AccountUpdatedMessage>(this);
var initialRequest = new BreadcrumbNavigationRequested(Translator.MenuManageAccounts, WinoPage.AccountManagementPage); var initialRequest = new BreadcrumbNavigationRequested(Translator.MenuManageAccounts, WinoPage.AccountManagementPage);
PageHistory.Add(new BreadcrumbNavigationItemViewModel(initialRequest, true)); PageHistory.Add(new BreadcrumbNavigationItemViewModel(initialRequest, true));
@@ -40,6 +46,16 @@ public sealed partial class ManageAccountsPage : ManageAccountsPageAbstract,
AccountPagesFrame.Navigate(accountManagementPageType, null, new SuppressNavigationTransitionInfo()); AccountPagesFrame.Navigate(accountManagementPageType, null, new SuppressNavigationTransitionInfo());
} }
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
// Explicitly unregister our message handlers before base.OnNavigatingFrom calls UnregisterAll
WeakReferenceMessenger.Default.Unregister<BreadcrumbNavigationRequested>(this);
WeakReferenceMessenger.Default.Unregister<BackBreadcrumNavigationRequested>(this);
WeakReferenceMessenger.Default.Unregister<MergedInboxRenamed>(this);
WeakReferenceMessenger.Default.Unregister<AccountUpdatedMessage>(this);
base.OnNavigatingFrom(e);
}
void IRecipient<BreadcrumbNavigationRequested>.Receive(BreadcrumbNavigationRequested message) void IRecipient<BreadcrumbNavigationRequested>.Receive(BreadcrumbNavigationRequested message)
{ {
@@ -26,6 +26,9 @@ public sealed partial class SettingsPage : SettingsPageAbstract, IRecipient<Brea
{ {
base.OnNavigatedTo(e); base.OnNavigatedTo(e);
// Re-register the breadcrumb navigation handler after base.OnNavigatedTo unregisters all handlers
WeakReferenceMessenger.Default.Register<BreadcrumbNavigationRequested>(this);
SettingsFrame.Navigate(typeof(SettingOptionsPage), null, new SuppressNavigationTransitionInfo()); SettingsFrame.Navigate(typeof(SettingOptionsPage), null, new SuppressNavigationTransitionInfo());
var initialRequest = new BreadcrumbNavigationRequested(Translator.MenuSettings, WinoPage.SettingOptionsPage); var initialRequest = new BreadcrumbNavigationRequested(Translator.MenuSettings, WinoPage.SettingOptionsPage);
@@ -58,6 +61,14 @@ public sealed partial class SettingsPage : SettingsPageAbstract, IRecipient<Brea
settingsHeader.Title = Translator.MenuSettings; settingsHeader.Title = Translator.MenuSettings;
} }
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
// Explicitly unregister our message handlers before base.OnNavigatingFrom calls UnregisterAll
WeakReferenceMessenger.Default.Unregister<BreadcrumbNavigationRequested>(this);
base.OnNavigatingFrom(e);
}
void IRecipient<BreadcrumbNavigationRequested>.Receive(BreadcrumbNavigationRequested message) void IRecipient<BreadcrumbNavigationRequested>.Receive(BreadcrumbNavigationRequested message)
{ {
var pageType = ViewModel.NavigationService.GetPageType(message.PageType); var pageType = ViewModel.NavigationService.GetPageType(message.PageType);