问题描述
我开发一个WPF应用程序用C#和上午pretty的新的这个技术。我知道,当我点击运行,即按Ctrl + F5运行我的程序可以打开应用程序窗口,适当的小部件。我试图找出是否其可能基于一些检测条件,即打开不同的窗口,如果某些条件得到满足我想打开一个特定的窗口,但如果它不是我想要打开另一扇窗。
I am developing a WPF application with C#, and am pretty new to this technology. I know that when I run my program by clicking "Run" i.e "Ctrl + F5" it opens the application window with appropriate widgets. I am trying to find out if its possible to open different windows based on some check condition i.e if some condition is satisfied I wish to open a particular window, but if its not I want to open another window.
应该是这样打开的任何窗口之前,应该首先检查的条件像
It should be like before opening any window it should first check for the condition like
if(File.Exists(<path-to-file>)
Open Window 1
else
Open Window 2
这可能吗?
推荐答案
考虑的App.xaml
look into App.xaml
删除的StartupUri =MainWindow.xaml
添加启动=Application_Startup
新的事件处理程序
<Application x:Class="YourProject.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="Application_Startup">
背后App.xaml.cs形式code创建Application_Startup像...
form code behind App.xaml.cs create Application_Startup like...
private void Application_Startup(object sender, StartupEventArgs e)
{
//add some bootstrap or startup logic
var identity = AuthService.Login();
if (identity == null)
{
LoginWindow login = new LoginWindow();
login.Show();
}
else
{
MainWindow mainView = new MainWindow();
mainView.Show();
}
}
这篇关于WPF - 选择基于一定条件下启动窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!