找不到StaticResource引用。 [英] StaticResource reference was not found.

查看:320
本文介绍了找不到StaticResource引用。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设计师给我一个"未找到StaticResource引用"。如果我的App.xaml位于项目下的子目录中,则引用应用程序资源的错误。即使设计师抱怨,代码构建并运行良好。

例如在一个全新的WPF应用程序项目中:

在App.xaml:

< Application.Resources >
< 样式 x =" RedLabel" TargetType =" { x Type Label }" ;>
< Setter 属性 =" Foreground" Value =" Red" />
< / < font color ="#a31515"size = 1>样式 >
< ; / Application.Resources >

在Window1中。 xaml

< 标签 样式 =" { < font color ="#a31515"size = 1> StaticResource RedLabel }" 内容 ="测试标签" />


在这一点上,设计师很高兴显示Window1.xaml。但后来我在我的WpfApplication1下添加了文件夹src并将App.xaml和Window1.xaml移入其中。

当我尝试查看Window1.xaml时,我收到错误"StaticResource reference'RedLabel'未找到" ;.然而,代码编译并按预期运行。




























>
感谢您报告此问题。如果app.xaml不在项目的根目录中,我可以确认WPF设计器在应用程序定义文件(app.xaml)中定义了问题查找资源。此问题正在作为产品错误进行跟踪。

目前的解决方法是不要更改app.xaml的位置。

再次感谢,2009年新年快乐。

Zhanbo

The designer gives me a "StaticResource reference was not found." error for references to application resources, if my App.xaml is in a subdirectory under the project. Even though the designer complains, the code builds and runs fine.

For example in a brand new WPF Application project:

In App.xaml:

<Application.Resources>
    <Style x:Key="RedLabel" TargetType="{x:Type Label}">
        <Setter Property="Foreground" Value="Red"/>
    </Style>
</Application.Resources>

In Window1.xaml

<Label Style="{StaticResource RedLabel}" Content="Test Label"/>


At this point the designer is happy to display Window1.xaml. But then I add the folder src under my WpfApplication1 and move App.xaml and Window1.xaml into it.

When I attempt to view Window1.xaml I get the error "StaticResource reference 'RedLabel' was not found.". The code however compiles and runs as expected.


    - David

解决方案

Hi, David,

Thanks for reporting this issue. I can confirm that WPF designer has issue finding resources defined within application definition file (app.xaml) if app.xaml is not on the root directory of the project. This issue is being tracked as a product bug.

The current workaround is not to change the location of app.xaml.

Thanks again, and Happy New Year of 2009.

Zhanbo


这篇关于找不到StaticResource引用。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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