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) {