WPF与传统的windows页面程序类似,但也有一些区别:
启动页:
方法一:
在App.xaml文件中修改StartupUri的值。
方法二:在App.xaml.cs 后台代码中声明Main()方法、
[STAThread]
static void Main()
{
Window2 win = new Window2();
Application app = new Application();
app.Run(win);
}
方法三:
[STAThread]
static void Main()
{
Window2 win = new Window2();
Application app = new Application();
app.MainWindow = win; win.Show();
app.Run();
}
方法四:
[STAThread]
static void Main()
{
Application app = new Application();
app.StartupUri = new Uri("Window2.xaml", UriKind.Relative);
app.Run();
}
在窗体window1.xaml中:
<Window x:Class="Demo_1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window with button" Height="300" Width="300">
<Button Name="button" Click="button_Click">click me</Button>
</Window>
其中:x:Class="Demo_1.Window1"指明了要与后台代码相关联的类,button的事件用特性语法注明了单击事件。