Im busy with my app and i walked in some problems when i click on a photo in my listbox PhotoFeed.
I got 1 List<> with in it the strings UrlTumb and UrlFull.
I got 1 ListBox with in it a WrapPanel filled with images wich i set the Image.Source from my UrlTumb.
What my problem is when i click on a photo in my listbox i want to navigate to a new page and display there the original image (UrlFull) now i can only get my UrlTumb from my Image.Source but i want my UrlFull which is stored in the List. Now is my question how do i obtain the UrlFull. So how can i back trace which item i clicked and get the UrlFull from that item so i can send it with my NavigationService.Navigate
I can do it on an dirty way and create an invisible textblock besides the image in my ListBox and put the UrlFull in there but i would like to do it in a proper way
So what do i place in the ????? spot in this line
NavigationService.Navigate(new Uri("/PhotoInfo.xaml?urlfull={0}", ????? , UriKind.Relative));
Greetings Cn
There are multiple options:
listBox.SelectedIndexto get the indexof the selected property which will correspond to the index in your
source (it might not if you filter the collection using collection
source, but I think that is not the case)
listBox.SelectedItemthis will return theSelectedItem which will contain your object. (Note, that if your
selection mode set to multiple, this will return only the firstly
selected item)
SelectemItems. It will allow you to get an array of selecteditems (Note: this should be normally used only when your list’s
selection mode is set to multiple)
SelectedValue, which will contain the value of the SelectedItem(this will save you and extra step.
Bellow is the code snippet of 3 options above. x, y, z will all be your selected names (e.g. “Mike”)
XAML:
Code behind:
For the differences between SelectedValue and SelectedItem refer here SelectedItem vs SelectedValue