加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-13 20:12:42 所属栏目:Windows 来源:网络整理
导读:我正在开发 Windows Phone应用程序. 我正在使用图像,当我使用“属性”面板选择图片时,我得到以下XAML: Image x:Name="GameImage" Margin="8" Source="/MyApp;component/Assets/Icons/GameImage.png"/ 为什么我得到“/ MyApp;组件/ …”? (有更好的方法吗?
我正在开发 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读