mirror of
https://github.com/PacktPublishing/Learn-WinUI-3-Second-Edition.git
synced 2026-06-20 12:23:09 +00:00
Add chapter 10 sample project
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using TemplateStudioSampleApp.Helpers;
|
||||
|
||||
using Windows.UI.ViewManagement;
|
||||
|
||||
namespace TemplateStudioSampleApp;
|
||||
|
||||
public sealed partial class MainWindow : WindowEx
|
||||
{
|
||||
private Microsoft.UI.Dispatching.DispatcherQueue dispatcherQueue;
|
||||
|
||||
private UISettings settings;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
AppWindow.SetIcon(Path.Combine(AppContext.BaseDirectory, "Assets/WindowIcon.ico"));
|
||||
Content = null;
|
||||
Title = "AppDisplayName".GetLocalized();
|
||||
|
||||
// Theme change code picked from https://github.com/microsoft/WinUI-Gallery/pull/1239
|
||||
dispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();
|
||||
settings = new UISettings();
|
||||
settings.ColorValuesChanged += Settings_ColorValuesChanged; // cannot use FrameworkElement.ActualThemeChanged event
|
||||
}
|
||||
|
||||
// this handles updating the caption button colors correctly when indows system theme is changed
|
||||
// while the app is open
|
||||
private void Settings_ColorValuesChanged(UISettings sender, object args)
|
||||
{
|
||||
// This calls comes off-thread, hence we will need to dispatch it to current app's thread
|
||||
dispatcherQueue.TryEnqueue(() =>
|
||||
{
|
||||
TitleBarHelper.ApplySystemThemeToCaptionButtons();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user