简体   繁体   English

从其他项目调用时未加载XAML资源

[英]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.

相关问题 SplashScreen实施后未加载WPF资源 - WPF Resources aren't loaded after SplashScreen implementation 在其他类中实例化UserControl时,不使用资源中的样式 - Styles from resources aren't used when UserControl is instantiated in other class xaml引用的依赖项不是从项目文件夹中加载的,而是从可执行文件文件夹中加载的 - Dependencies referenced by xaml are not loaded from project folder but from executable folder 具有共享项目和XAML的字符串资源 - String Resources with Shared Project and XAML 来自父XAML类的TreeView在不同的项目中但在相同的命名空间中不存在于“当前上下文”中 - TreeView from parent XAML class does not exist in “current context” when in different project but same namespace 从资源中使用图标时,仅显示 XAML 中的最后一个图标 - Only last icon in XAML shown when icon used from resources 将图像从资源添加到XAML - Adding image from Resources to XAML 覆盖同一解决方案中另一个项目的Generic.xaml资源字典资源 - Override Generic.xaml Resource Dictionary resources from another project in same solution 不能在 xaml WPF 中使用来自其他项目的控制 - Can't use control from other project in xaml WPF 从 XAML 调用参数化构造函数 - Calling a parameterized constructor from XAML
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM