为什么XAML图像源属性包含“/ MyApp; component”?

我正在开发 Windows Phone应用程序.

我正在使用图像,当我使用“属性”面板选择图片时,我得到以下XAML:

<Image x:Name="GameImage" Margin="8" Source="/MyApp;component/Assets/Icons/GameImage.png"/>

为什么我得到“/ MyApp;组件/ …”? (有更好的方法吗?)

如果我尝试做Image.Source =“资产/图标/ GameImage.png”为什么它不起作用?

这是因为您的图像将其构建操作设置为资源(这是默认值).如果将其切换到内容,您可以像XAML那样设置源:
<Image x:Name="GameImage" Margin="8" Source="/Assets/Icons/GameImage.png"/>

要设置代码,你可以这样做:

BitmapImage tn = new BitmapImage();
tn.SetSource(Application.GetResourceStream(new Uri(@"Assets/Icons/GameImage.png",UriKind.Relative)).Stream);
Image.Source = tn;

出于性能原因,您应该使用内容.请参阅这篇文章了解更多细节:http://www.windowsphonegeek.com/tips/wp7-working-with-images-content-vs-resource-build-action

相关文章

文章浏览阅读2.2k次,点赞6次,收藏20次。在我们平时办公工作...
文章浏览阅读1k次。解决 Windows make command not found 和...
文章浏览阅读3.2k次,点赞2次,收藏6次。2、鼠标依次点击“计...
文章浏览阅读1.3w次。蓝光版属于高清版的一种。BD英文全名是...
文章浏览阅读974次,点赞7次,收藏8次。提供了更强大的功能,...
文章浏览阅读1.4w次,点赞5次,收藏22次。如果使用iterator的...