为什么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

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...