这个Urikind相关的究竟是什么意思 [英] What exactly mean by this Urikind.relative
问题描述
我在做什么是我会有一个datagridview当我选择一行,点击显示按钮我想显示图像以及一些信息,我写了以下代码
What i am doing is i will have a datagridview when i select a row and click on show button i would like to display the image along with some information for that i written the following code
public partial class WpfWindow : Window
{
private UCPersons _ucPersons;
public WpfWindow()
{
InitializeComponent();
// Create WinForms Usercontrol and
// add it to the WindowsFormsHost
_ucPersons = new UCPersons();
winFormHost.Child = _ucPersons;
List<Person> persons = CreateSamplePersons();
_ucPersons.SetData(persons);
}
private List<Person> CreateSamplePersons()
{
List<Person> persons = new List<Person>();
persons.Add(Person.Create("Dorababu", "Madhuranagar", "Hyd",
DateTime.Now.AddYears(-34), "1"));
persons.Add(Person.Create("Krish", "Sat", "RJY",
DateTime.Now.AddYears(-64), "2"));
return persons;
}
private void btnDisplayDetails_Click(object sender, RoutedEventArgs e)
{
Person person = _ucPersons.GetSelectedPerson();
if (person != null)
{
lblName.Content = person.Name;
lblAge.Content = person.BirthDay.ToShortDateString();
Uri uri = new Uri( "m_" + person.ImageRef + ".jpg",
UriKind.Relative);
imgPerson.Source = BitmapFrame.Create(uri);
}
}
}
但同样没有工作如果我复制并粘贴我的图像从Bin。
But the same is not working if i copy and paste my images out of Bin.
所以我想知道一些关于这个 UriKInd
So i would like to know some thing about this UriKInd
推荐答案
相对于绝对。 chicken / pot / pie.jpg将是相对的,因为它与当前目录相对相对。而像C:/images/food/chicken/pot/pie.jpg这样的东西就是绝对,因为它相对于根驱动器。
Relative, as opposed to Absolute. "chicken/pot/pie.jpg" would be relative, because it's relative to the current directory. Whereas something like "C:/images/food/chicken/pot/pie.jpg" would be absolute because it's ...err... relative to the root of the drive.
以这种方式初始化Uri的唯一真正原因是当uri格式不正确时避免(或引起)异常;当Uri不是预定时有用的。
The only real point to initializing the Uri this way is to avoid (or cause) exceptions when the uri is not well-formed; useful when the Uri is not predetermined.
相对和绝对URI对其格式有不同的限制。例如,相对URI不需要方案或权限。您在
uriKind
中指定的值必须与uriString
中传递的URI类型相匹配。但是,如果指定了 RelativeOrAbsolute ,URI字符串可以是相对或绝对。
Relative and absolute URIs have different restrictions on their format. For example, a relative URI does not require a scheme or an authority. The value you specify in
uriKind
must match the type of URI passed inuriString
. However, if RelativeOrAbsolute is specified, the URI string can be relative or absolute.
这篇关于这个Urikind相关的究竟是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!