windows - 如何通过 UWP 在 XAML C# 中显示图像?

标签 windows universal

我一直在网上查找,但似乎无法找到如何将简单图像添加到我的 UWP 项目中。只是希望它能在我的项目中正确显示。

这是我的一些代码:

<Image x:Name="img" HorizontalAlignment="Left" Height="27" Margin="1,4,0,0" VerticalAlignment="Top" Width="29" Source="E:\MyTestApp\MyTestApp\Assets\youtube-subscribe-button-2.png"/>

最佳答案

您不能将图片的来源设置为您使用过的路径。据我所知,您不能引用磁盘上的任意文件作为图像的源(至少不能通过 XAML 中的路径)。

您可以在 XAML 中引用您添加到项目中的图像。根据该路径,您似乎已经完成了该操作(因为它在您的 Assets 目录中)。

如果您的 XAML 页面与 Assets 目录位于同一目录中,那么您可以使用相对路径:

<Image Source="Assets/youtube-subscribe-button-2.png" />

或者您可以使用与 XAML 页面文件所在位置无关的绝对路径:

<Image Source="ms-appx:///Assets/youtube-subscribe-button2.png" />

参见 Image.Source propertyHow to load file resources (XAML)

关于windows - 如何通过 UWP 在 XAML C# 中显示图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38799699/

相关文章:

python - 在 PyInstaller 应用程序中启用 Windows 长文件路径支持

Windows 7 64 Chrome 19 字体抗锯齿渲染问题

windows - 从提供程序读取数据时发生错误。根据验证程序,远程证书无效

windows - 在 Windows 中启动后立即自动终止进程

iPhone 在通用应用程序中检查运行时的常量

windows - 通过ViewModel自定义UWP ListViewItem

尝试使用 angular2-universal-starter 时 angular2 组件未呈现

css - 通用选择器 (*) 是否与 :last-child work in all mobile browsers? 组合

c# - 在 Windows Universal App 中使用 StatusBar

android - 有没有办法将 Xamarin.forms 添加到通用 Windows 应用程序 (UWP)?