我有一个正在开发的 Silverlight 应用程序。我有一些不同的自定义按钮样式,它们使用 ContentTemplate 将图像显示为按钮,例如:
<Style x:Key="CancelButtonStyle" TargetType="Button">
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Image Source="Assets/Images/Controls/cancel.png"/>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
cancel.png 是最近添加的图像,它没有显示。如果我将一个简单的图像添加到一个页面,并将源设置为此图像,我会在 XMAL 设计查看器中看到带有警告的下划线
The file 'Assets/Images/Controls/cancel.png' is not part of the project or its 'Build Action' property is not set to 'Resource'
我已经仔细检查过,它的构建操作设置为“资源”。我已经卸载了项目并查看了 csproj 文件,并且有一个用于此图像的构建条目,我错过了什么?我对这张图片没有做任何与我对同一文件夹中的其他图片不同的事情。
更新
如果我使用以下方法,我可以在设计时看到图像,但在运行时看不到图像,有什么想法吗?
<Image Source="Foo.Bar;component/Assets/Images/Controls/cancel.png" Stretch="None"/>
最佳答案
我使用以下图片来源解决了这个问题:
Source="/Foo.Bar;component/Assets/Images/Controls/cancel.png"
虽然我仍然不确定问题的根源。
关于silverlight - 在 Silverlight 4 应用程序中显示新图像资源时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3236173/