找传奇、传世资源到传世资源站!

WPF开发(插件管理、tab切换)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

在主界面框架中,我们依靠第三方控件库"ModernUI"来实现界面,并对"ModernUI"做深入的定制。在界面框架插件引用该控件时,首先,我们需要将该插件添加到Manifest.xml作为本地程序集,即界面框架插件在运行时需要与该程序集一起才能够正常运行。 WPF开发(插件管理、tab切换) 桌面应用界面/GUI-第1张
WPF开发(插件管理、tab切换) 桌面应用界面/GUI-第2张

  1. var bundleRuntime = new BundleRuntime();
  2. bundleRuntime.AddService();
  3. bundleRuntime.Start();

注意:主程序在BundleRuntime.Start方法调用前注册的服务,插件在启动时即可获取。这时候,插件可以在激活器中直接获取到该服务了。

  1. public class Activator : IBundleActivator
  2. {
  3. public void Start(IBundleContext context)
  4. {
  5. var sayHelloService = context.GetFirstOrDefaultService();
  6. sayHelloService.Hell("Lorry Chen");
  7. }
  8. public void Stop(IBundleContext context)
  9.     {
  10.     
  11.     }
  12. }

using System;using System.Collections.Generic;using System.Configuration;using System.Data;using System.Linq;using System.Threading.Tasks;using System.Windows;using UIShell.OSGi;using UIShell.PageFlowService;using UIShell.OSGi.Logging;using UIShell.iOpenWorks.Bootstrapper;namespace UIShell.iOpenWorks.WPF{ /// <summary> /// WPF startup class. /// </summary> public partial class App : Application { // Use object type to avoid load UIShell.OSGi.dll before update. private object _bundleRuntime; public App() { UpdateCore(); StartBundleRuntime(); } void UpdateCore() // Update Core Files, including BundleRepositoryOpenAPI, PageFlowService and OSGi Core assemblies. { if (AutoUpdateCoreFiles) { new CoreFileUpdater().UpdateCoreFiles(CoreFileUpdateCheckType.Daily); } } void StartBundleRuntime() // Start OSGi Core. { var bundleRuntime = new BundleRuntime(); bundleRuntime.AddService<Application>(this); bundleRuntime.Start(); Startup = App_Startup; Exit = App_Exit; _bundleRuntime = bundleRuntime; } void App_Startup(object sender, StartupEventArgs e) { Application app = Application.Current; var bundleRuntime = _bundleRuntime as BundleRuntime; app.ShutdownMode = ShutdownMode.OnLastWindowClose; #region Get the main window var pageFlowService = bundleRuntime.GetFirstOrDefaultService<IPageFlowService>(); if (pageFlowService == null) { throw new Exception("The page flow service is not installed."); } if (pageFlowService.FirstPageNode == null || string.IsNullOrEmpty(pageFlowService.FirstPageNode.Value)) { throw new Exception("There is not first page node defined."); } var windowType = pageFlowService.FirstPageNodeOwner.LoadClass(pageFlowService.FirstPageNode.Value); if (windowType == null) { throw new Exception(string.Format("Can not load Window type '{0}' from Bundle '{1}'.", pageFlowService.FirstPageNode.Value, pageFlowService.FirstPageNodeOwner.SymbolicName)); } app.MainWindow = System.Activator.CreateInstance(windowType) as Window; #endregion app.MainWindow.Show(); } void App_Exit(object sender, ExitEventArgs e) { if (_bundleRuntime != null) { var bundleRuntime = _bundleRuntime as BundleRuntime; bundleRuntime.Stop(); _bundleRuntime = null; } } #region Settings /// <summary> /// 日志级别。 /// </summary> private static LogLevel LogLevel { get { string level = ConfigurationSettings.AppSettings["LogLevel"]; if (!string.IsNullOrEmpty(level)) { try { object result = Enum.Parse(typeof(LogLevel), level); if (result != null) { return (LogLevel)result; } } catch { } } return LogLevel.Debug; } } /// <summary> /// 日志文件限制的大小。 /// </summary> private static int MaxLogFileSize { get { string size = ConfigurationSettings.AppSettings["MaxLogFileSize"]; if (!string.IsNullOrEmpty(size)) { try { return int.Parse(size); } catch { } } return 10; } } /// <summary> /// 当日志大小超过限制时,是否新建一个。 /// </summary> private static bool CreateNewLogFileOnMaxSize { get { string createNew = ConfigurationSettings.AppSettings["CreateNewLogFileOnMaxSize"]; if (!string.IsNullOrEmpty(createNew)) { try { return bool.Parse(createNew); } catch { } } return false; } } /// <summary> /// 当日志大小超过限制时,是否新建一个。 /// </summary> private static bool AutoUpdateCoreFiles { get { string autoUpdateCoreFiles = ConfigurationSettings.AppSettings["AutoUpdateCoreFiles"]; if (!string.IsNullOrEmpty(autoUpdateCoreFiles)) { try { return bool.Parse(autoUpdateCoreFiles); } catch { } } return false; } } #endregion }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复