WPF应用程序设置启动时自动打开的第一个窗口的几种方式

来源:互联网 发布:云计算和物联网 编辑:程序博客网 时间:2024/06/06 06:57

方法一:

<Application
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="mytest.App"
    Startup="app_Startup">
</Application>

using System.Windows;
namespace mytest
{
    public partial class App : Application
    {
        void app_Startup(object sender, StartupEventArgs e)
        {
            // Create a window
            Windows1 window = new Windows1();

            // Open a window
            window.Show();
        }
    }

 

 

方法二:

<Application
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="mytest.App"
    StartupUri="Windows2.xaml" />

方法二比较简单,用的比较多:),如果在启动的时候需要做一些判断,方法一就灵活一些