When running my program by clicking Run
or pressing Ctrl + F5
, is it 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
Is this possible?
look into App.xaml
remove
StartupUri="MainWindow.xaml"
add
Startup="Application_Startup"
new event Handlerform code behind App.xaml.cs create Application_Startup like...
You can use
App.xaml
to start up your application and, as Nikhil Agrawal said, changeStartupUri
dynamically.However, you can still start up your application from
public static void Main()
. Just delete theStartupUri="MainWindow.xaml"
attribute inApp.xaml
, Add aProgram
class to your project containing aMain
method, and then go to the project properties and set the startup object toYourAssemblyName.Program
.Note, the
STAThreadAttribute
is required. If you need your own derived version ofApplication
, such as how WPF projects create a derivedApp
class by default, you can use that in theMain
in place ofApplication
. But, if you don't need it, you can just use the baseApplication
class directly and remove the derived one from your project.In
App.xaml
we have anApplication
tag havingStartupUri
attribute. I think u should write this code in App.xaml.cs sectionand set
StartUpUri
to desired xaml file.