[英]XAML resources aren't loaded when calling from different project
I have a WPF project with some styles in XAML in Application.Resources
. 我在Application.Resources
中的XAML中有一个具有某些样式的WPF项目。 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. 但是,当我从另一个项目(该项目是一个控制台应用程序)打开该项目的窗口时,不会加载XAML的资源。 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. 第一次尝试时,我在XAML中的StaticResource
调用上遇到了XamlParseException
,因此将其更改为DynamicResource
,现在样式就没有加载。 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. 您应该调用带有Window
参数的Run
方法。 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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.