未找到 wpf 资源但仍在应用 [英] wpf resource is not found but still applied

查看:29
本文介绍了未找到 wpf 资源但仍在应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的解决方案中有几个项目包含它们自己的资源.我确保它们在主 App.xaml 中定义:

I'm having several projects in my solution which contain their own resources. I make sure they are defined in main App.xaml:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
           <ResourceDictionary Source="pack://application:,,,/MainMenu;component/Resources/Resources.xaml" />
           <ResourceDictionary Source="pack://application:,,,/Main;component/Resources/Resources.xaml" />
    </ResourceDictionary.MergedDictionaries>

应用每个 Resources.xaml 中的内容.但是在设计器中,当我使用它们时,它们会出现错误:

the content in each Resources.xaml is applied. but in the designer when I'm using them they appear with error:

<TextBlock
    Style="{StaticResource MainWindowTitleStyle}" />

无法解析资源MainWindowTitleStyle".

The resource "MainWindowTitleStyle" could not be resolved.

如何避免这些错误?

推荐答案

VS 2012 Designer 仍然存在一些问题,这就是其中之一.

There are stil some problems in the VS 2012 Designer, and this is one of them.

您可以将您的 StaticResource 引用更改为 DynamicResource,这应该可以防止设计人员抛出这些仅限设计时的异常.

You can change your StaticResource references to DynamicResource and this should prevent the designer from throwing these design-time-only exceptions.

这篇关于未找到 wpf 资源但仍在应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆