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
You can use App.xaml
to start up your application and, as Nikhil Agrawal said, change StartupUri
dynamically.
However, you can still start up your application from public static void Main()
. Just delete the StartupUri="MainWindow.xaml"
attribute in App.xaml
, Add a Program
class to your project containing a Main
method, and then go to the project properties and set the startup object to YourAssemblyName.Program
.
[STAThread]
public static void Main(string[] args)
{
var app = new Application();
var mainWindow = new MainWindow();
app.Run(mainWindow);
}
Note, the STAThreadAttribute
is required. If you need your own derived version of Application
, such as how WPF projects create a derived App
class by default, you can use that in the Main
in place of Application
. But, if you don't need it, you can just use the base Application
class directly and remove the derived one from your project.