[Peek] Set button color on theme change (#26564)

* [WIP] Set button color manually

* Remove unused aliases
This commit is contained in:
Stefan Markovic
2023-06-07 16:52:47 +02:00
committed by GitHub
parent 026db38457
commit 40335a6998
2 changed files with 35 additions and 3 deletions

View File

@@ -4,12 +4,12 @@
using System;
using interop;
using ManagedCommon;
using Microsoft.PowerToys.Telemetry;
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Input;
using Peek.Common.Constants;
using Peek.Common.Helpers;
using Peek.FilePreviewer.Models;
using Peek.UI.Extensions;
using Peek.UI.Helpers;
@@ -23,15 +23,20 @@ namespace Peek.UI
/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainWindow : WindowEx
public sealed partial class MainWindow : WindowEx, IDisposable
{
public MainWindowViewModel ViewModel { get; }
private ThemeListener themeListener;
public MainWindow()
{
InitializeComponent();
this.Activated += PeekWindow_Activated;
themeListener = new ThemeListener();
themeListener.ThemeChanged += (_) => HandleThemeChange();
ViewModel = App.GetService<MainWindowViewModel>();
NativeEventWaiter.WaitForEventLoop(Constants.ShowPeekEvent(), OnPeekHotkey);
@@ -41,6 +46,20 @@ namespace Peek.UI
AppWindow.Closing += AppWindow_Closing;
}
private void HandleThemeChange()
{
AppWindow appWindow = this.GetAppWindow();
if (ThemeHelpers.GetAppTheme() == AppTheme.Light)
{
appWindow.TitleBar.ButtonForegroundColor = Colors.DarkSlateGray;
}
else
{
appWindow.TitleBar.ButtonForegroundColor = Colors.White;
}
}
private void PeekWindow_Activated(object sender, Microsoft.UI.Xaml.WindowActivatedEventArgs args)
{
if (args.WindowActivationState == Microsoft.UI.Xaml.WindowActivationState.Deactivated)
@@ -203,5 +222,10 @@ namespace Peek.UI
return false;
}
public void Dispose()
{
themeListener?.Dispose();
}
}
}

View File

@@ -226,6 +226,14 @@ namespace Peek.UI.Views
appWindow.TitleBar.ExtendsContentIntoTitleBar = true;
appWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;
appWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
if (ThemeHelpers.GetAppTheme() == AppTheme.Light)
{
appWindow.TitleBar.ButtonForegroundColor = Colors.DarkSlateGray;
}
else
{
appWindow.TitleBar.ButtonForegroundColor = Colors.White;
}
mainWindow.SetTitleBar(this);
}