silverlight - 在 Silverlight 4 应用程序中显示新图像资源时出现问题

标签 silverlight xaml silverlight-4.0

我有一个正在开发的 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/

相关文章:

c# - 具有多个 ColorAnimations 的 Silverlight Storyboard

wpf - 如何在 XAML 中实例化 ControlTemplate?

wpf - 从整数天数绑定(bind)到显示值和单位(日、周、月)的 WPF UserControl

c# - 数据绑定(bind)到 ComboBox 中的 CollectionViewSource 时如何保留 CurrentItem 的双向绑定(bind)

c# - Bing 在 C# 中映射 silverlight 控件

c# - 为什么要使用 DataForm?

c# - 添加新的 ApplicationBarMenuItem 图标时无法分配给属性

c# - Windows Phone 应用程序在不同设备上的测试

c# - 如何关闭应用栏(Windows 8 Metro)

silverlight - 如何通过 Silverlight 发送 UDP 多播数据包?