我正在开发适用于 Windows 8 的 Metro UI 应用程序,并且正在尝试从项目文件夹中检索图像。
这是我的初始代码:
public static Image GetImage(string path, int width, int height, int margin)
{
Image img = new Image();
img.Width = width;
img.Height = height;
img.Margin = new Windows.UI.Xaml.Thickness(margin);
BitmapImage bi = new BitmapImage(new Uri(path, UriKind.Absolute));
img.Source = bi;
return img;
}
和方法调用:
Image = Extension.GetImage("Classe;component/Images/faq.png", 100, 100, 0);
和错误:
Exception:Thrown: "Invalid URI: The format of the URI could not be determined." (System.UriFormatException)
A System.UriFormatException was thrown: "Invalid URI: The format of the URI could not be determined."
如果我将 URI 类型更改为相对:
Exception:Thrown: "The given System.Uri cannot be converted into a Windows.Foundation.Uri. Please see http://go.microsoft.com/fwlink/?LinkID=215849 for details." (System.ArgumentException)
A System.ArgumentException was thrown: "The given System.Uri cannot be converted into a Windows.Foundation.Uri. Please see http://go.microsoft.com/fwlink/?LinkID=215849 for details."
图片路径是图片/faq.png。设置为内容并始终复制。