1,直接指定StartupUri為某一個window的子類Window1.xaml(屬性指定法)
<Application x:Class="brush.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml">2,通過Startup來指定目前隐藏CS代碼的類(brush.App類)的一個方法 MyApplication_Startup(事件指定法)
<Application x:Class="brush.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="MyApplication_Startup" >上面兩種方法都用到了App.xaml(前台表現) 及App.xaml.cs (背景實作),這就是一個Application的執行個體, 事實上在程式進入入口時已
啟動了Application執行個體。如果同時指定StartupUri及Startup,不會發生編譯錯誤,但會打開兩個視窗。
3.在背景編輯StartupUri及Startup
如,在InitializeComponent()方法中,設定了StartupUri屬性:
this.Startup += new System.Windows.StartupEventHandler(this.Application_Startup);
this.StartupUri = new System.Uri("Window1.xaml", System.UriKind.Relative);
它是對App.xaml中的Startup="Application_Startup”和StartupUri="Window1.xaml"翻譯。
4.在入口函數裡改
app.xaml中x:Class屬性把xaml所對應的背景C#類聯系起來,在這裡是WpfApplication1.App,其中App是類名,WpfApplication1是命名空間。App.xaml在編譯後産生一個部分類,它位于所建立的項目目錄下的obj\Debug子目錄中,檔案名為App.g.cs。這個檔案中的内容如下:
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using System.Windows.Media.TextFormatting;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication1 {
/// <summary>
/// App
/// </summary>
public partial class App : System.Windows.Application {
/// <summary>
/// Application Entry Point.
/// </summary>
[System.STAThreadAttribute()]
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
public static void Main() {
WpfApplication2.App app = new WpfApplication1.App();
app.Run();
}
}
}
可在Main函數裡面修改啟動項。注意,app裡面隻能存在一個程式入口函數,即這裡的Main函數,否則會編譯錯誤。當然,你也完全可以把App.g.cs裡面的Main函數移到App.xaml.cs檔案裡面,因為他們都是部分類。這樣就可以通過入口函數來修改啟動窗體。
本文來自CSDN部落格,轉載請标明出處:http://blog.csdn.net/a0700746/archive/2010/04/18/5499450.aspx
轉載于:https://www.cnblogs.com/elaborateday/archive/2010/10/31/1865843.html