如何使用带有caliburn的应用程序同时用于控制台和WPF? [英] How to have a application with caliburn for both console and wpf?

查看:62
本文介绍了如何使用带有caliburn的应用程序同时用于控制台和WPF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个应支持批处理模式"的应用程序.因此,我们希望使其可以从控制台调用,就像devenv.exe一样.

We have an application that shall support a "batch mode". So we want to make it callable from the console, just like devenv.exe.

该应用程序具有WPF用户界面,这是大多数用户的默认界面.我们在主窗口中使用带有引导程序的caliburn.micro.

The application has a WPF user interface, which is the default interface for most users. We use caliburn.micro with a bootstrapper for the mainwindow.

认为我们应该为此使用不同的引导程序.(或者根本没有引导程序)

Think we should have a different bootstrapper for that. (Or no bootstrapper at all)

  1. 我们如何选择"环境是什么?
  2. 在引导程序开始工作之前,有什么方法可以做吗?

推荐答案

如果我正确理解了您的问题,那么您希望以控制台模式(来自CMD)或UI模式运行应用程序使用WPF界面,正确吗?.

If I understand your question correctly then you want to run the application either in console mode (from the CMD) or in UI mode with the WPF interface, correct ?.

认为我们应该为此使用不同的引导程序.(或者根本没有引导程序)

Think we should have a different bootstrapper for that. (Or no bootstrapper at all)

您可以保留引导程序,但是可能需要对其进行一些修改,使其看起来像这样:

You can keep the bootstrapper, but you may need to modify it a bit so it looks like this:

public class AppBootstrapper : BootstrapperBase
{

     public AppBootstrapper()
     {
         Start(); // THIS IS WHAT CAUSES THE FRAMEWORK TO INITIALIZE
     }

     protected override void Configure()
     {  
         // DIFFERENT CONFIGURATION GOES HERE
     }

     protected override object GetInstance(Type service, string key)
     {
         // DI CONTAINER RELATED CONFIGURATION
     }

     protected override IEnumerable<object> GetAllInstances(Type service)
     {
         // DI CONTAINER RELATED CONFIGURATION
     }

     protected override void BuildUp(object instance)
     {
         // DI CONTAINER RELATED CONFIGURATION
     }

     protected override void OnStartup(object sender, System.Windows.StartupEventArgs e)
     {
         // ANY CUSTOM BEFORE-START CUSTOMIZATION OR PROCESSING CAN TAKE PLACE HERE
         DisplayRootViewFor<SPECIFIY_ROOT_VIEW_MODEL_HERE>(); // THIS IS WHAT DISPLAYS THE MAIN WINDOW, IF YOU DON'T CALL THIS NO UI WILL BE SHOWN
     }
}

我们如何选择"环境是什么?

How can we "choose" what the environment is?

在上面在引导程序中显示的 OnStartup()覆盖中,并且在 DisplayRootViewFor 调用之前,可以通过调用

In the OnStartup() override shown above in the bootstrapper and before the DisplayRootViewFor call, you can obtain a list of command line arguments by calling Environment.GetCommandLineArgs() and then perhaps you could ask users who want to work in batch mode to specify an argument, and based on that you could or could not call DisplayRootViewFor to show the main window.

在引导程序开始工作之前,有什么方法可以做吗?

Is there any way to do anything before the bootstrapper begins his job?

是的,您最好在 OnStartup()方法中执行此操作,或者如果希望在 Configure()方法中进行操作.

Yes, you can do that in the OnStartup() method preferably or if you wish in the Configure() method.

注意:除非您调用 Start(),否则 Configure() OnStartup()都不会被调用.code>在构造函数中.

Note: Both Configure() and OnStartup() won't get called unless you call Start() in the constructor.

这篇关于如何使用带有caliburn的应用程序同时用于控制台和WPF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆