mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 09:46:54 +02:00
[Peek] Set button color on theme change (#26564)
* [WIP] Set button color manually * Remove unused aliases
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user