From 0717f95c9c33d3475e71ddb62501695e5e9e557f Mon Sep 17 00:00:00 2001 From: JLdgu Date: Wed, 11 Mar 2026 08:32:08 +0000 Subject: [PATCH] Browser background not being set to grey in production Only happens when Windows Dark mode is selected --- .../Features/Phones/EmailView.xaml.cs | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/PhoneAssistant.WPF/Features/Phones/EmailView.xaml.cs b/PhoneAssistant.WPF/Features/Phones/EmailView.xaml.cs index 8a4dc9d..4457be2 100644 --- a/PhoneAssistant.WPF/Features/Phones/EmailView.xaml.cs +++ b/PhoneAssistant.WPF/Features/Phones/EmailView.xaml.cs @@ -1,20 +1,35 @@ -using System.Windows.Controls; +using System.ComponentModel; +using System.Windows.Controls; namespace PhoneAssistant.WPF.Features.Phones; public partial class EmailView : UserControl -{ +{ public EmailView() { InitializeComponent(); - InitializeAsync(); + + // Don't run the WebView2 initialization when the XAML designer is active + if (DesignerProperties.GetIsInDesignMode(this)) + return; + + _ = InitializeAsync(); } - async void InitializeAsync() + async Task InitializeAsync() { + try + { + if (WebView2 is null) + return; - await WebView2.EnsureCoreWebView2Async(null); - //WebView2.CoreWebView2.Profile.PreferredColorScheme = Microsoft.Web.WebView2.Core.CoreWebView2PreferredColorScheme.Light; - WebView2.DefaultBackgroundColor = System.Drawing.Color.LightGray; + await WebView2.EnsureCoreWebView2Async(null); + WebView2.CoreWebView2?.Profile.PreferredColorScheme = Microsoft.Web.WebView2.Core.CoreWebView2PreferredColorScheme.Light; + WebView2.DefaultBackgroundColor = System.Drawing.Color.LightGray; + } + catch (Exception) + { + // Swallow exceptions during initialization to avoid crashing the XAML designer + } } private void DeliveryAddress_TextChanged(object sender, TextChangedEventArgs e) {