[Wpf学习] 1.传说中的Main
原来的C#程序都有Main的,现在用vs新建一个Wpf项目,启动似乎变成App.xmal,前期项目中为了获取启动参数,很是折腾了一番:
1.先是修改App.xaml,添加StartUp事件
<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数组
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完善了一下
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); } } }
相关推荐
Morelia 2020-11-03
love0u 2020-08-16
xiaouncle 2020-07-31
踩风火轮的乌龟 2020-07-26
THEEYE 2020-06-25
DAV数据库 2020-06-17
lightlanguage 2020-06-13
kuoying 2020-06-07
地下库 2020-05-29
HappyHeng 2020-05-28
lysanderK 2020-05-26
Caleb0 2020-05-08
boredbird 2020-05-06
<add key="RedisPath" value="127.0.0.1:6379"/> todo:这里配置自己redis的ip地址和端口号。//ReadServerList:可读的Redis链接地
天空一样的蔚蓝 2020-05-05
cyydjt 2020-05-04
TyCoding 2020-05-03