如果我使用Caliburn Micro作为MVVM框架,以使我的应用程序作为GUI或作为命令行应用程序运行(因此它可以作为Windows服务使用),我需要做什么改变。
不要声明一个 StartupUri
而是注册到 StartUp
在你 Application
.
在事件中,你可以阅读一个论点,以区分打开一个 Window
或不。
所以,比如说
App. xaml
<Application x:Class="WpfApp1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApp1"
Startup="App_OnStartup">
</Application>
App.xaml.cs
public partial class App : Application
{
private void App_OnStartup(object sender, StartupEventArgs e)
{
if (e.Args.Contains("Console"))
{
//do stuff
}
else
{
new MainWindow().Show();
}
}
}