日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

初学WPF之程序启动几种方式

發(fā)布時間:2025/3/15 asp.net 57 豆豆
生活随笔 收集整理的這篇文章主要介紹了 初学WPF之程序启动几种方式 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1、第一種是默認的方式,通過app.xaml中的StartupUri="MainWindow.xaml"配置的。

1 <Application x:Class="BaseElement.App" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 StartupUri="MainWindow.xaml"> 5 <Application.Resources> 6 </Application.Resources> 7 </Application> View Code

2、第二種是通過創(chuàng)建Application對象來啟動程序。同時右擊工程->屬性->應(yīng)用程序->啟動對象設(shè)為Startup就行了。

1 public class Startup 2 { 3 [STAThread] 4 public static void Main() 5 { 6 7 // Create the application. 8 Application app = new Application(); 9 // Create the main window. 10 MainWindow win = new MainWindow(); 11 // Launch the application and show the main window. 12 app.Run(win); 13 } 14 } View Code

3、第三種是修改App.xaml.cs文件。添加Main方法。同時刪除app.g.cs文件中Main方法

1 /// <summary> 2 /// App.xaml 的交互邏輯 3 /// </summary> 4 public partial class App : Application 5 { 6 7 [STAThread()] 8 public static void Main() 9 { 10 BaseElement.App app = new BaseElement.App(); 11 app.InitializeComponent(); 12 app.Run(); 13 } 14 public void InitializeComponent() 15 { 16 this.StartupUri = new Uri("MainWindow.xaml", System.UriKind.Relative); 17 } 18 } View Code

4、第四種也是修改App.xaml.cs文件,和第三種不太一樣。此方法還包括了如果傳遞command-line arguments(命令行參數(shù))

1 public partial class App : Application 2 { 3 [STAThread] 4 public static void Main() 5 { 6 App app = new App(); 7 app.Run(); 8 } 9 10 public App() 11 { 12 this.Startup += new StartupEventHandler(App_Startup); 13 } 14 15 private static void App_Startup(object sender, StartupEventArgs e) 16 { 17 // Create, but don't show the main window. 18 MainWindow win = new MainWindow(); 19 if (e.Args.Length > 0) 20 { 21 string file = e.Args[0]; 22 if (System.IO.File.Exists(file)) 23 { 24 // Configure the main window. 25 win.LoadFile(file); 26 } 27 } 28 else 29 { 30 // (Perform alternate initialization here when 31 // no command-line arguments are supplied.) 32 } 33 // This window will automatically be set as the Application.MainWindow. 34 win.Show(); 35 } 36 } View Code

第一次寫博客,如果有什么問題請多多包含,我也是剛剛學(xué)習(xí)wpf,還是菜鳥!

轉(zhuǎn)載于:https://www.cnblogs.com/homingfly/p/3961627.html

總結(jié)

以上是生活随笔為你收集整理的初学WPF之程序启动几种方式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。