using System; using System.Windows; namespace Sinvo.EplanHpD.Plugin.WPFUI.Extension { public static class ApplicationExt { /// /// 设置主窗口 /// /// /// /// public static void SetMainWindow(this Application application, Window window) { if (application == null) { throw new ArgumentNullException(nameof(application)); } if (window == null) { throw new ArgumentNullException(nameof(window)); } application.MainWindow = window; } /// /// 初始化应用程序,修复在某些情况下,引用第三方UI控件库的时候出现的异常与卡顿 /// public static void InitApplication() { if (Application.Current == null) { new System.Windows.Application { ShutdownMode = ShutdownMode.OnExplicitShutdown, Resources = new ResourceDictionary { Source = new Uri("pack://application:,,,/Sinvo.EplanHpD.Plugin.WPFUI;component/Themes/Theme.xaml") }, }; Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException; } } private static void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { HandyControl.Controls.MessageBox.Show($"{sender.GetType()}: {e.Exception.Message}"); e.Handled = true; } } }