我对 WPF 中的 StartUp Url 有疑问。我有一个 LoginView.xaml 和 MainWindow.xaml。我想首先打开 LoginView,然后自动打开 MainWindow。
应用程序.xaml
<Application x:Class="XXX.App"
xmlns="....."
Startup="App_Startup"
>
应用程序.xaml.cs
/
// <summary>
/// Called when the application starts.
/// </summary>
private void App_Startup(object sender, StartupEventArgs e)
{
LoginView frmLogin = new LoginView();
bool? resultScreen = frmLogin.ShowDialog();
if (frmLogin.ShowDialog())
{
Uri uri = new Uri("pack:/MainWindow.xaml", UriKind.RelativeOrAbsolute);
Application.Current.StartupUri = uri;
}
else
{
Application.Current.Shutdown();
}
}
LoginView 窗口正常打开,之后什么也没发生,应用程序关闭。
我尝试了另一种方法,但我得到了相同的结果。
应用程序.xaml
<Application x:Class="XXX.App"
xmlns="....."
Startup="App_Startup"
>
应用程序.xaml.cs
/// <summary>
/// Called when the application starts.
/// </summary>
private void App_Startup(object sender, StartupEventArgs e)
{
LoginView frmLogin = new LoginView();
bool? resultScreen = frmLogin.ShowDialog();
if frmLogin.ShowDialog())
{
MainWindow frmMainWindow = new MainWindow();
frmMainWindow.ShowDialog();
}
else
{
Application.Current.Shutdown();
}
}
谁能告诉我,我怎样才能得到想要的结果?提前致谢。