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

前端之家收集整理的这篇文章主要介绍了为什么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

原文链接:https://www.f2er.com/windows/371177.html

猜你在找的Windows相关文章