简体   繁体   中英

XAML resources aren't loaded when calling from different project

I have a WPF project with some styles in XAML in Application.Resources . This works perfectly fine. But when I open a window from this project from another one (this one is a console application), the resources from XAML aren't loaded. When I first tried it, I got a XamlParseException on StaticResource calls in XAML, so I changed it to DynamicResource and now the style just doesn't get loaded. How do I fix this?

The code I use:

[STAThread]
static void Main()
{
    App app = new App();
    MyWindow wnd = new MyWindow ();
    wnd.Show();
    app.Run();
}

You should call the Run method that takes a Window parameter. In your current code, you're creating and showing the window before running the app, which means the application resources aren't loaded yet.

Try:

App app = new App();
MyWindow wnd = new MyWindow();
app.Run(wnd);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM