using System; using System.Windows; namespace TestSeq { public class GlobalConfig { public double GlobalFontSize { get; set; } = 14; } public class GlobalConfigHolder { public static GlobalConfig Config { get; internal set; } } /// /// Interaction logic for App.xaml /// public partial class App : Application { public App() { AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException; ; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; } private void CurrentDomain_FirstChanceException(object sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e) { //var ex = e.Exception; //MessageBox.Show(ex?.Message, "未知错误"); } private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { var ex = e.ExceptionObject as Exception; // Log.Error($"UnhandledException. {ex}"); MessageBox.Show(ex?.Message, "未知错误"); } protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); // 放在最后,确保后续逻辑用到时已在内存 } public void Application_Startup(object sender, StartupEventArgs e) { MainWindow window = new MainWindow(); window.Show(); } } }