这是一个非常简单的问题,但我似乎找不到答案。我有一个WPF应用程序,为其制作了许多窗口。现在我决定,在启动应用程序时使用另一个窗口作为第一个打开的窗口。默认的第一个窗口是MainWindow,如何更改它以便先打开另一个窗口?
这个问题很容易解决。您可以在App.xaml文件中找到StartupUri属性并将其更改为所需窗口的URI。例如,如果您想要名为"NewWindow"的窗口成为第一个打开的窗口,则应将StartupUri属性更改为“NewWindow.xaml”。
打开你的 App.xaml 文件并更新 StartupUri:
<Application x:Class="WpfHacking.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml"> <!-- This is the line you want to update -->
</Application>
您也可以通过在App.xaml.cs中覆盖'OnStartup'方法来完成此操作,如下所示。
请注意从App.xaml中删除“StartupUri =“Test.xaml”
protected override void OnStartup(StartupEventArgs e)
{
Test window = new Test();
window.Show();
}