using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace Laservall.Solidworks.Extension
{
public static class WPFApplicationExt
{
///
/// 设置主窗口
///
///
///
///
//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:,,,/Laservall.Solidworks;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;
}
}
}