I have a WPF-Application with 3 xaml files: App.xaml, StartWindow.xaml and MainWindow.xaml. If I start the application, I want to show either StartWindow or MainWindow depending on a condition. My solution is to write a custom Main method in App.xaml.cs:
public static String DEBUG = "true";
[STAThread]
static void Main()
{
App app = new App();
if (/*condition*/)
app.Run(new MainWindow());
else
app.Run(new StartWindow());
}
The App.xaml property build action is set to "Page". (I followed this guide: Guide, although it still works with StartupUri set to "MainWindow.xaml" and without App()).
The StartWindow constructor has following code:
public StartWindow()
{
InitializeComponent();
Task.Run(() =>
{
// Some initialization code
Console.WriteLine(App.DEBUG);
Application.Current.Dispatcher.Invoke(() =>
{
MainWindow mainWindow = new MainWindow();
mainWindow.Show();
this.Close();
});
});
}
This works perfectly fine on my development machine, but not on a different one (Virtual machine with same OS and target .NetFramework installed). If I set a Breakpoint after Console.WriteLine(App.DEBUG), it prints out the string on both environments, but the properties look different and also shortly after that it throws an exception:
Properties on breakpoint:
Exception (Text says "can't find ressource "mainwindow.xml""):
Properties on breakpoint on my development machine where it works:
Why is it still looking for MainWindow.xml, or even stanger mainwindow.xaml? And why only on one machine?



base.StartupUri = new Uri("MainWindow.xaml", UriKind.Relative); if (!_contentLoaded) { _contentLoaded = true; Uri resourceLocater = new Uri("/...;component/app.xaml", UriKind.Relative); Application.LoadComponent(this, resourceLocater); }While it doesnt look correct at first, how can it work on one machine and not the other? - notan