C# - Windows 通用应用程序 - 图像源不起作用

标签 c# windows windows-phone win-universal-app

我正在尝试在 Windows Universal 应用程序中为我的图像定义源,但出现以下错误:

Invalid URI: The format of the URI could not be determined.

imagePath = "Assets/Category-other-dark.png";
Uri uri = new Uri(imagePath, UriKind.Absolute);
ImageSource imgSource = new BitmapImage(uri);
imgCategory.Source = imgSource;

我搜索了很多论坛并尝试了很多东西,但没有任何效果。谢谢。

最佳答案

将其更改为:

imagePath = "ms-appx:///Assets/Category-other-dark.png";
Uri uri = new Uri(imagePath, UriKind.RelativeOrAbsolute);
ImageSource imgSource = new BitmapImage(uri);
imgCategory.Source = imgSource;

关于C# - Windows 通用应用程序 - 图像源不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30921191/

相关文章:

c# - 如何使用 C# 检查是否激活了 Windows 功能

windows - 如何检查计划在Windows中运行哪些程序?

c# - Windows Phone 8 中的依赖注入(inject)

c# - RestSharp 无效的 URI : The URI Scheme is not valid

c# - BitmapImage 缺少 BeginInit() 和 EndInit() 函数?

c# - 转义 C#,有点困惑

c# - 从类库创建 vsix 包

c# - 表单发布时将下拉列表中的选定值从 View 传递到 Controller

c# - 如何用 NewtonSoft 的 Json Serializer 替换 OData V4 默认的 Json Serializer?

windows - Electron:是否可以检索文件上次访问的日期和时间