From 40cbbc7d55088852d1effeec4aea69a1b37aa05c Mon Sep 17 00:00:00 2001 From: lihanbo Date: Fri, 15 Nov 2024 15:02:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20ApplicationExt=20=E9=9D=99?= =?UTF-8?q?=E6=80=81=E7=B1=BB=E5=8F=8A=E5=88=9D=E5=A7=8B=E5=8C=96=E8=B0=83?= =?UTF-8?q?=E7=94=A8=EF=BC=8C=E8=A7=A3=E5=86=B3=E5=9B=A0=E4=B8=BA=E6=9C=AA?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E4=B8=BB=E6=9C=BA=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84=E6=89=BE=E4=B8=8D=E5=88=B0=E8=B5=84=E6=BA=90=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 ApplicationExt.cs 文件中添加了一个新的静态类 ApplicationExt,包含 SetMainWindow 和 InitApplication 方法。更新 DesignPluginEntry.cs 和 PluginEntry.cs 文件,引入 Sinvo.EplanHpD.Plugin.WPFUI.Utils 命名空间,并在 Initialize 方法中调用 ApplicationExt.InitApplication 方法。 --- .../Utils/ApplicationExt.cs | 35 +++++++++++++++++++ Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs | 7 ++++ Sinvo.EplanHpD.Plugin/PluginEntry.cs | 3 +- 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 Sinvo.EplanHpD.Plugin.WPFUI/Utils/ApplicationExt.cs diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ApplicationExt.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ApplicationExt.cs new file mode 100644 index 0000000..5f29bde --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ApplicationExt.cs @@ -0,0 +1,35 @@ +using System; +using System.Windows; + +namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils +{ + 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; + } + 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") + } + }; + } + } + } +} diff --git a/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs b/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs index 740898f..abbf52e 100644 --- a/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs +++ b/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs @@ -1,6 +1,7 @@ using EPLAN.Harness.API; using EPLAN.Harness.API.Plugins.Core; using Sinvo.EplanHpD.Plugin.WPFUI; +using Sinvo.EplanHpD.Plugin.WPFUI.Utils; using System; using System.Drawing; using System.IO; @@ -9,7 +10,11 @@ using System.Windows.Forms.Integration; namespace Sinvo.EplanHpD.Plugin { +#if DEBUG public class DesignPluginEntry : EPLAN.Harness.API.Plugins.IHpDPlugin +#else + public class DesignPluginEntry +#endif { public string Name => "兴禾ProD插件-3D"; @@ -55,6 +60,8 @@ namespace Sinvo.EplanHpD.Plugin public void Initialize() { AppDomainDllLoader.SetLaoder(); + ApplicationExt.InitApplication(); + } diff --git a/Sinvo.EplanHpD.Plugin/PluginEntry.cs b/Sinvo.EplanHpD.Plugin/PluginEntry.cs index a9bd831..65f4c35 100644 --- a/Sinvo.EplanHpD.Plugin/PluginEntry.cs +++ b/Sinvo.EplanHpD.Plugin/PluginEntry.cs @@ -4,6 +4,7 @@ using EPLAN.Harness.API.Plugins.Core; using EPLAN.Harness.Core.Controls; using EPLAN.Harness.ProjectCore; using Sinvo.EplanHpD.Plugin.WPFUI; +using Sinvo.EplanHpD.Plugin.WPFUI.Utils; using System; using System.Drawing; using System.IO; @@ -142,7 +143,7 @@ namespace Sinvo.EplanHpD.Plugin { //throw new NotImplementedException(); AppDomainDllLoader.SetLaoder(); - + ApplicationExt.InitApplication(); } public void Terminate()