1,在app.xaml中去掉StartupUri=“MainWindow.xaml”;
<Application x:Class="LotteryDraw.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:LotteryDraw">
</Application>
2,在App.xaml.cs中添加以下启函数,判断启动参数中是否存在 “XXXXXXX”; 如果不存在,则不启动;
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);//测试发现隐藏后也可正常运行,等待老司机帮忙解惑
// 接收参数数组
var args = e.Args;
// 定义为字符数组也可以
//string[] args = e.Args;
// 判断参数中是否包含 TestWindows
if (args.Contains("XXXXXXX"))
{
new MainWindow().Show();
}
else
{
base.Shutdown();
}
}
参考连接:https://www.cnblogs.com/jeremywucnblog/p/12666976.html
[好文共赏析!]