Windows 8 Windows 8应用程序:为什么必须在图像源URL中指定ms appx://?

Windows 8 Windows 8应用程序:为什么必须在图像源URL中指定ms appx://?,windows-8,Windows 8,我一直在查看,在该示例中加载图像的XAML如下所示: <Image Source="Assets/image1.jpg"/> <Image Source="ms-appx:///Assets/image1.jpg"/> 然而,在我自己的项目中,我发现我无法加载任何这样的图像。如果我尝试,当我处理图像失败时,我会得到E_NETWORK_错误。相反,我发现我必须使用ms appx:///前缀,如下所示: <Image Source="Assets/image1.

我一直在查看,在该示例中加载图像的XAML如下所示:

<Image Source="Assets/image1.jpg"/>
<Image Source="ms-appx:///Assets/image1.jpg"/>

然而,在我自己的项目中,我发现我无法加载任何这样的图像。如果我尝试,当我处理图像失败时,我会得到E_NETWORK_错误。相反,我发现我必须使用ms appx:///前缀,如下所示:

<Image Source="Assets/image1.jpg"/>
<Image Source="ms-appx:///Assets/image1.jpg"/>

然后它就起作用了。是否知道我的项目与导致此问题的示例有什么不同?

-在Windows 8 RTM/Visual Studio 2012 RTM中进行了测试,可以确认不需要ms appx://前缀。您使用的是什么版本

如何设置映像或为其选择什么构建操作可能存在问题


此外,这在

中有说明。您是否尝试过“
对于声明性图像,您不需要ms appx名称空间(在XAML中声明的图像)。对于动态数据绑定图像,将创建一个新的位图实例,并且它需要此名称空间

解决此问题的一个好方法是从将命名空间作为共享属性实现的基础对象派生数据对象:

Private Shared _baseUri As New Uri("ms-appx:'''")

'//image handling
Private _image As ImageSource
Private _imagePath As String
Public Property Image As ImageSource
    Get
        If Me._image Is Nothing AndAlso Me._imagePath IsNot Nothing Then
            Me._image = New BitmapImage(New Uri(dataModelBase._baseUri, Me._imagePath))
        End If
        Return Me._image
    End Get

    Set(value As ImageSource)
        Me._imagePath = Nothing
        Me.SetProperty(Me._image, value)
    End Set
End Property

我用这个在Windows phone 8上工作


OrderImage1.Source=新位图图像(新Uri(“///Assets/images/order\u bread.png”));

您的xaml是否在自己的文件夹中?图像引用是相对的,因此如果您在文件夹中启动,您需要先执行
离开它。这只是因为我的xaml文件位于子目录中。出于某种原因,我假设路径是相对于项目根目录的。我很笨。