From 1ff82e62ff906dc521fbd3d41502eb956bc577f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Kaan=20K=C3=B6se?= Date: Fri, 12 Jul 2024 19:01:16 +0200 Subject: [PATCH] Remove BackdropMaterial usage in XAML for WinUI 3 --- .../Interfaces/IApplicationResourceManager.cs | 1 + Wino.Mail.WinUI/Wino.Mail.WinUI.csproj | 5 ++ Wino.Mail/AppShell.xaml | 1 - Wino.Mail/AppShell.xaml.cs | 47 ++++++++++++++++--- Wino.Mail/Helpers/XamlHelpers.cs | 3 +- .../Services/ApplicationResourceManager.cs | 3 ++ 6 files changed, 51 insertions(+), 9 deletions(-) diff --git a/Wino.Core.Domain/Interfaces/IApplicationResourceManager.cs b/Wino.Core.Domain/Interfaces/IApplicationResourceManager.cs index a8e1b22c..8024c5d1 100644 --- a/Wino.Core.Domain/Interfaces/IApplicationResourceManager.cs +++ b/Wino.Core.Domain/Interfaces/IApplicationResourceManager.cs @@ -7,5 +7,6 @@ bool ContainsResourceKey(string resourceKey); void ReplaceResource(string resourceKey, object resource); T GetLastResource(); + TReturn GetResource(string resourceKey); } } diff --git a/Wino.Mail.WinUI/Wino.Mail.WinUI.csproj b/Wino.Mail.WinUI/Wino.Mail.WinUI.csproj index 5ec0ba57..56883ae9 100644 --- a/Wino.Mail.WinUI/Wino.Mail.WinUI.csproj +++ b/Wino.Mail.WinUI/Wino.Mail.WinUI.csproj @@ -15,6 +15,7 @@ + @@ -118,6 +119,7 @@ + @@ -162,6 +164,9 @@ + + MSBuild:Compile + MSBuild:Compile diff --git a/Wino.Mail/AppShell.xaml b/Wino.Mail/AppShell.xaml index d38e9067..f8f886f2 100644 --- a/Wino.Mail/AppShell.xaml +++ b/Wino.Mail/AppShell.xaml @@ -17,7 +17,6 @@ xmlns:muxc="using:Microsoft.UI.Xaml.Controls" xmlns:selectors="using:Wino.Selectors" x:Name="Root" - muxc:BackdropMaterial.ApplyToRootOrPageBackground="{ThemeResource UseMica}" mc:Ignorable="d"> diff --git a/Wino.Mail/AppShell.xaml.cs b/Wino.Mail/AppShell.xaml.cs index bb376c67..5f2219c6 100644 --- a/Wino.Mail/AppShell.xaml.cs +++ b/Wino.Mail/AppShell.xaml.cs @@ -6,10 +6,7 @@ using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Messaging; using Windows.ApplicationModel.Core; using Windows.Foundation; -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Controls.Primitives; -using Windows.UI.Xaml.Input; + using Wino.Controls; using Wino.Core.Domain; using Wino.Core.Domain.Entities; @@ -25,6 +22,20 @@ using Wino.Mail.ViewModels.Data; using Wino.MenuFlyouts; using Wino.MenuFlyouts.Context; using Wino.Views.Abstract; +using Microsoft.UI.Xaml.Controls; + +#if NET8_0 +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Input; +using Microsoft.UI.Xaml.Navigation; +#else +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls.Primitives; +using Windows.UI.Xaml.Input; +using Windows.UI.Xaml.Navigation; +#endif namespace Wino.Views { @@ -32,7 +43,8 @@ namespace Wino.Views IRecipient, IRecipient, IRecipient, - IRecipient + IRecipient, + IRecipient { public AppShell() : base() { @@ -40,6 +52,12 @@ namespace Wino.Views var coreTitleBar = CoreApplication.GetCurrentView().TitleBar; coreTitleBar.LayoutMetricsChanged += TitleBarLayoutUpdated; + +#if !NET8_0 + // BackdropMaterial is not available in WinUI 3.0. + // We manually apply it for UWP version only. + SetupMica(); +#endif } private void TitleBarLayoutUpdated(CoreApplicationViewTitleBar sender, object args) => UpdateTitleBarLayout(sender); @@ -200,7 +218,7 @@ namespace Wino.Views } } - private void ShellFrameContentNavigated(object sender, Windows.UI.Xaml.Navigation.NavigationEventArgs e) + private void ShellFrameContentNavigated(object sender, NavigationEventArgs e) => RealAppBar.ShellFrameContent = (e.Content as BasePage).ShellContent; private void BackButtonClicked(Controls.Advanced.WinoAppTitleBar sender, RoutedEventArgs args) @@ -298,5 +316,22 @@ namespace Wino.Views ShellInfoBar.IsOpen = true; }); } + + + private void SetupMica() + { +#if !NET8_0 + var resourceManager = App.Current.Services.GetService>(); + + if (resourceManager.ContainsResourceKey("UseMica")) + { + bool isMicaEnabled = resourceManager.GetResource("UseMica"); + + BackdropMaterial.SetApplyToRootOrPageBackground(this, isMicaEnabled); + } +#endif + } + + public void Receive(ApplicationThemeChanged message) => SetupMica(); } } diff --git a/Wino.Mail/Helpers/XamlHelpers.cs b/Wino.Mail/Helpers/XamlHelpers.cs index 72ba29f7..a1c53e1e 100644 --- a/Wino.Mail/Helpers/XamlHelpers.cs +++ b/Wino.Mail/Helpers/XamlHelpers.cs @@ -9,8 +9,6 @@ using Wino.Core.Domain.Models.MailItem; using Wino.Core.Domain.Models.Reader; using Windows.UI.Text; - - #if NET8_0 using Microsoft.UI; using Microsoft.UI.Text; @@ -28,6 +26,7 @@ using Windows.UI.Xaml.Media; using Microsoft.Toolkit.Uwp.Helpers; using Windows.UI.Xaml.Shapes; #endif + namespace Wino.Helpers { public static class XamlHelpers diff --git a/Wino.Mail/Services/ApplicationResourceManager.cs b/Wino.Mail/Services/ApplicationResourceManager.cs index 58a773f2..98f63a5c 100644 --- a/Wino.Mail/Services/ApplicationResourceManager.cs +++ b/Wino.Mail/Services/ApplicationResourceManager.cs @@ -23,5 +23,8 @@ namespace Wino.Services public void ReplaceResource(string resourceKey, object resource) => App.Current.Resources[resourceKey] = resource; + + public TReturn GetResource(string resourceKey) + => (TReturn)App.Current.Resources[resourceKey]; } }