Heyho...
My WPF application has a customized startup to show a custom splash screen and doing some preparation (e.g. parsing arguments, prepare filesystem, ...). For this I override the OnStartup Method.
App.xaml.cs
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var splash = new SplashWindow();
splash.Show();
// do some black magic
splash.Close();
var mw = new MainWindow();
mw.Show();
}
}
}
App.xaml
<Application x:Class="Example.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApp1"
ShutdownMode="OnExplicitShutdown">
<Application.Resources>
<ResourceDictionary>
<Color x:Key="Foo">#FFFFAA00</Color>
<SolidColorBrush x:Key="Bar" Color="{StaticResource Foo}" />
</ResourceDictionary>
</Application.Resources>
</Application>
But handling the start up this way I cannot access resources defined in app.xaml i.e., in MainWindow.xaml or Splash.xaml.
Some other had already the same issue, i.e., https://stackoverflow.com/a/13425695
Following the workaround link takes me to this stackoverflow post: https://stackoverflow.com/a/3896209/5663348
The suggested workaround is to define x:Name
of the Application element. But how does it help me accessing the defined resource? Unfortunately the link for "more information" is broken (too old)...
Applying the accepted answer of this question does even not solve the problem.
I'm using .Net Framework 7.4.2
Can someone give me some hints, how I can solve this?
Cheers and thanks :)
=================
Problem solved... The real world app had initialized MainWindow and SplashWindow while the App class was instanciated... stupid mistake...