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实例
请看App.xaml.cs
namespace brush { public partial class App : Application { private void MyApplication_Startup(object sender, StartupEventArgs e) { MessageBox.Show("Application Start ..........."); Thread.Sleep(5000); Window myXamlWindow = new Window1(); myXamlWindow.Show(); } } }
通过这个文件中的命名空间和类的定义可以很容易地看出 上面的App.xmal 里的x:class=”brush.App”就是指定App类,而App类却是继承了Application类
注:有些地方说可以通过下面的静态Main来启动程序,可我实现不了,不知道为什么? 请高手指点.....
namespace brush { //不知道如何做这种XAML的入口程序 public partial class appStart :Application { public static void Main(string[] args) { Window myWpf = new Window1(); myWpf.Show(); } } }
转自:http://www.cnblogs.com/CsharpBlog/archive/2009/10/12/1582053.html