原來的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);
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/67577.html
標籤:其他
