From 35189bd1fe832be4c1c502eec38779807cd68dd4 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Mon, 3 Jun 2024 13:47:29 -0500 Subject: [PATCH] Fix possible nullref assignments on Wasdk --- CommunityToolkit.App.Shared/App.xaml.cs | 8 ++++---- CommunityToolkit.App.Shared/Pages/Shell.xaml.cs | 2 +- CommunityToolkit.App.Shared/Pages/TabbedPage.xaml.cs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CommunityToolkit.App.Shared/App.xaml.cs b/CommunityToolkit.App.Shared/App.xaml.cs index 5e5ca39a..ba5c5884 100644 --- a/CommunityToolkit.App.Shared/App.xaml.cs +++ b/CommunityToolkit.App.Shared/App.xaml.cs @@ -12,10 +12,10 @@ namespace CommunityToolkit.App.Shared; public sealed partial class App : Application { // MacOS and iOS don't know the correct type without a full namespace declaration, confusing it with NSWindow and UIWindow. - // Using static will not work. -#if WINAPPSDK - public static Microsoft.UI.Xaml.Window currentWindow = Microsoft.UI.Xaml.Window.Current; -#else + // 'using static' will not work. +#if WINUI3 + public static Microsoft.UI.Xaml.Window? currentWindow = Microsoft.UI.Xaml.Window.Current; +#elif WINUI2 private static Windows.UI.Xaml.Window? currentWindow = Windows.UI.Xaml.Window.Current; #endif diff --git a/CommunityToolkit.App.Shared/Pages/Shell.xaml.cs b/CommunityToolkit.App.Shared/Pages/Shell.xaml.cs index 8615df7f..2480cf14 100644 --- a/CommunityToolkit.App.Shared/Pages/Shell.xaml.cs +++ b/CommunityToolkit.App.Shared/Pages/Shell.xaml.cs @@ -20,7 +20,7 @@ public sealed partial class Shell : Page public Shell() { this.InitializeComponent(); -#if WINAPPSDK +#if WINDOWS_WINAPPSDK appTitleBar.Window = App.currentWindow; #else BackdropMaterial.SetApplyToRootOrPageBackground(this, true); diff --git a/CommunityToolkit.App.Shared/Pages/TabbedPage.xaml.cs b/CommunityToolkit.App.Shared/Pages/TabbedPage.xaml.cs index 9f3874ca..fdc1920d 100644 --- a/CommunityToolkit.App.Shared/Pages/TabbedPage.xaml.cs +++ b/CommunityToolkit.App.Shared/Pages/TabbedPage.xaml.cs @@ -34,7 +34,7 @@ public sealed partial class TabbedPage : Page public TabbedPage() { this.InitializeComponent(); -#if WINAPPSDK +#if WINDOWS_WINAPPSDK appTitleBar.Window = App.currentWindow; #else BackdropMaterial.SetApplyToRootOrPageBackground(this, true);