原来的C#程序都有Main的,如今用vs新建一个Wpf项目,启动彷佛变成App.xmal,前期项目中为了获取启动参数,非常折腾了一番:数组
1.先是修改App.xaml,添加StartUp事件app
<Application x:Class="YKMain.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:YKMain" Startup="Application_Startup">
2.而后编辑Application_Startup,判断e.Args数组async
private async void Application_Startup(object sender, StartupEventArgs e) { }
总感受跟又臭又长的裹脚布同样,不爽。学习后,找回了传说中的Main,莫有App.Xaml,直截了当。学习
using System; using System.Windows; namespace L1_NoXaml { public class Program : Application { [STAThread] static void Main(string[] args) { Program app = new Program(); app.MainWindow = new Window1(); app.MainWindow.ShowDialog(); } } }
PS:2020/3/3完善了一下spa
using System; using System.Windows; namespace YKMainCore { public class Program : Application { [STAThread] static void Main(string[] args) { SplashScreen splashScreen = new SplashScreen("id.png"); splashScreen.Show(true); MainWindow window = new MainWindow() { WindowStyle = WindowStyle.None, ResizeMode = ResizeMode.NoResize, WindowState = WindowState.Normal, ShowInTaskbar = false, Background = System.Windows.Media.Brushes.Transparent, AllowsTransparency = true, Left = 0, Top = 0, Width = SystemParameters.PrimaryScreenWidth, Height = SystemParameters.PrimaryScreenHeight }; Program app = new Program(); app.Run(window); } } }