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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22576588/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 11:17:54  来源:igfitidea点击:

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

c#wpf

提问by Datta

When try to execute it give an error. in my stand alone application

当尝试执行它时会出错。在我的独立应用程序中

hare is my code

野兔是我的代码

var uri = new Uri(@"Earnest_Indieiduals/image/qty15section3.jpg");
                qestion15.Source = new BitmapImage(uri);

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

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

enter image description here

在此处输入图片说明

回答by Rohit Vats

Use

var uri = new Uri(@"image/qty15section3.jpg", UriKind.Relative);

in case code you are trying to execute is written in assembly Earnest_Indieiduals.

如果您尝试执行的代码是在程序集 Earnest_Indieiduals 中编写的。

Also you can use Pack URI's.

您也可以使用Pack URI 的.

var uri = new Uri("pack://application:,,,/image/qty15section3.jpg",
                   UriKind.Absolute);

回答by NullReferenceException

Use like this

像这样使用

var uri = new Uri("/Earnest_Indieiduals;component/image/qty15section3.jpg", UriKind.Relative);
qestion15.Source = new BitmapImage(uri);

or

或者

var uri = new Uri("pack://application:,,,/image/qty15section3.jpg")
qestion15.Source = new BitmapImage(uri);