【问题标题】:C# - Windows Universal app - Image Source doesn't workC# - Windows 通用应用程序 - 图像源不起作用
【发布时间】:2015-06-18 16:44:55
【问题描述】:

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

无效的 URI:无法确定 URI 的格式。

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

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

【问题讨论】:

  • 我尝试了那篇文章中写的内容。
  • 您的 png 位置在哪里?应用包还是应用数据?

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


【解决方案1】:

改成:

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

【讨论】:

  • 我试过了,但是...'给定的 System.Uri 无法转换为 Windows.Foundation.Uri。'
  • @JanChalupa 接受它作为答案然后:)
  • 顺便说一句:ms-appxms-appdata 有什么区别?
【解决方案2】:

您必须使用本地、漫游或临时:

var uri = new System.Uri("ms-appdata:///local/Assets/logo.png");

【讨论】:

    【解决方案3】:

    试试这个

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

    【讨论】:

    • 我试过了,但是...'给定的 System.Uri 无法转换为 Windows.Foundation.Uri。'
    • 导入时检查你导入的包名。导入 System.Uri 而不是 Windows.Foundation.Uri
    • 同时导入什么?我不明白。原谅我的知识和英语不好。 :)
    猜你喜欢
    • 1970-01-01
    • 2012-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-06
    • 2021-07-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多