Take the 2-minute tour ×

I have a stack panel with multiple text blocks which are bound to parsed results from an XML file.

What I would like to is to make each results have an onlick event which would then link to more information or even a message.show box, but it must use a value from the results it displays.

This is the .Xaml section for the listbox which disaplys the results.)

<ListBox Height="435"
        <StackPanel Orientation="Horizontal"
            <Image Source="{Binding ImageSource}"
                   Height="150" Width="150"
            <StackPanel Width="370" >
                <TextBlock Text="{Binding Title}"
                           FontSize="16" />
                <TextBlock Text="{Binding PriceDisplay}" 
                           Foreground="Black" />
                <TextBlock Text="{Binding ListingId}" 
                           Foreground="Black" />
                <TextBlock Text="{Binding Region}" 
                           Foreground="Black" />

One of the text blocks returns a value for (ListingID). ideally when a user clicks this result they they will be taken to another page which will disaply more results based on the LIstingID form that results.

Listing ID is 400332970

Is there any way to carry that value to another page and use it in something like this? Where ListingID.XMl would be the listingId from the onClick result.

WebClient Trademe = new WebClient();
Trademe.DownloadStringCompleted += new DownloadStringCompletedEventHandler(Trademe_DownloadStringCompleted);
Trademe.DownloadStringAsync(new Uri("http://api.trademe.co.nz/v1/Listings/" + ListingID.xml));

I am sorry if this is confusing, I have tried to explain as best I can. Hopefully someone has an idea of what I am talking about.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

If I understand it correctly, you could use a QueryString to pass the information along to the next page.

//handle the selectionchanged event (replace 'myObject' with your object type)
void ListBoxSelectionChanged(object sender, SelectionChangedEventArgs args)
    var lbi = ((sender as ListBox).SelectedItem as myObject);
    if(lbi != null)
        string id = lbi.ListingId.ToString();
        NavigationService.Navigate("/NewPage.xaml?listingid=" + id, UriKind.Relative));    

Then, in your NewPage.xaml page, you can read the value of the query string. (You can add error checks, or use QueryString.TryGetValue instead to avoid exceptions).

string id = NavigationContext.QueryString["listingid"];

You can use id as part of the download code you posted.

share|improve this answer
wouldn't that pass all the listingID's? Rather than the one the the user clicks on ? There are around 20 different listings all with thier own ListingID –  Rhys Aug 19 '11 at 22:51
@Rhys: No it wouldn't. Presumably you tie the ListBox's ItemSource to some collection in code behind. The myObject mentioned in the answer above is an object from that collection. So the object corresponding to the selected item of the ListBox will contained only the listing ID of the ListBoxItem that was tapped. –  Praetorian Aug 19 '11 at 23:05
@keyboardP Ok, sounds like a solution for me then. I dont understand replaceing my object with object type? Do you mean String, Bool etc.? –  Rhys Aug 19 '11 at 23:19
What's the name of the class that has Title, PriceDisplay, ListingId and Region? That will be the object type in this case, so replace myObject with the name of that class. –  keyboardP Aug 20 '11 at 0:03
Ah I get it.. Thanks again for your help. Your a legend!! :) –  Rhys Aug 20 '11 at 0:45
show 4 more comments

Your Answer


