У меня есть файл XML, который связан со списком, как показано ниже. Отображается список из 20+ аукционов с каждым из следующих элементов.
listBox1.ItemsSource = from TM in r.Root.Descendants(ns + "Listing")
select new TradeItem
{
ImageSource = TM.Element(ns + "PictureHref").Value,
Title = TM.Element(ns + "Title").Value,
Region = TM.Element(ns + "Region").Value,
PriceDisplay = TM.Element(ns + "PriceDisplay").Value,
ListingId = TM.Element(ns + "ListingId").Value,
};
Я хочу, чтобы пользователь мог щелкнуть по одному из аукционов и передать его Listingid с аукциона на другую страницу, где я буду использовать этот Listingid, например, 40008598, чтобы отобразить конкретные детали этого аукциона, как показано ниже:
WebClient Detail = new WebClient();
Detail.DownloadStringCompleted += new DownloadStringCompletedEventHandler(Detail_DownloadStringCompleted);
Detail.DownloadStringAsync(new Uri("http://api.trademe.co.nz/v1/Listings/" + ***listingid from other previous page selection*** + ".xml"));
void Detail_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
return;
var r = XDocument.Parse(e.Result);
// Declare the namespace
XNamespace ns = "http://api.trademe.co.nz/v1";
ListingDetails.ItemsSource = from D in r.Descendants(ns + "ListedItemDetail").Take(20)
select new TradeItem
{
ImageSource = D.Element(ns + "Photos").Element(ns + "Photo").Element(ns + "Value").Element(ns + "Medium").Value,
Title = D.Element(ns + "Title").Value,
Region = D.Element(ns + "Region").Value,
PriceDisplay = D.Element(ns + "Body").Value,
ListingId = D.Element(ns + "ListingId").Value,
CloseDate = D.Element(ns + "EndDate").Value,
BuyNow = D.Element(ns + "BuyNowPrice").Value,
StartPrice = D.Element(ns + "StartPrice").Value,
};
Обновлен код с изменениями ################################################
First Page - View Auction Listings
namespace TradeMe
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
WebClient Trademe = new WebClient();
Trademe.DownloadStringCompleted += new DownloadStringCompletedEventHandler(Trademe_DownloadStringCompleted);
Trademe.DownloadStringAsync(new Uri ("http://api.trademe.co.nz/v1/Search/General.xml?search_string=" + TradeSearch.Text));
progressBar1.IsIndeterminate = true;
progressBar1.Visibility = Visibility.Visible;
}
void Trademe_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
return;
var r = XDocument.Parse(e.Result);
// Declare the namespace
XNamespace ns = "http://api.trademe.co.nz/v1";
listBox1.ItemsSource = from TM in r.Root.Descendants(ns + "Listing")
select new TradeItem
{
ImageSource = TM.Element(ns + "PictureHref").Value,
Title = TM.Element(ns + "Title").Value,
Region = TM.Element(ns + "Region").Value,
PriceDisplay = TM.Element(ns + "PriceDisplay").Value,
ListingId = TM.Element(ns + "ListingId").Value,
};
progressBar1.IsIndeterminate = false;
progressBar1.Visibility = Visibility.Collapsed;
}
public class TradeItem
{
public string Region { get; set; }
public string ListingId { get; set; }
public string PriceDisplay { get; set; }
public string Title { get; set; }
public string ImageSource { get; set; }
}
private void hyperlinkButton1_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/TestPage.xaml", UriKind.Relative));
}
private void eventhandler(object sender, SelectionChangedEventArgs e)
{
var item = (sender as ListBox).SelectedItem as TradeItem;
if (item != null)
{
string id = TradeItem.ListingId.ToString();
NavigationService.Navigate(new Uri("/TestPage.xaml?ListingId=" + id, UriKind.Relative));
}
}
}
}
Информация о просмотре второй страницы ################################################ ##
namespace TradeMe
{
public partial class TestPage : PhoneApplicationPage
{
public TestPage()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (NavigationContext.QueryString.ContainsKey("ListingId"))
{
var listingId = NavigationContext.QueryString["ListingId"];
WebClient Trademe = new WebClient();
Trademe.DownloadStringCompleted += new DownloadStringCompletedEventHandler(Trademe_DownloadStringCompleted);
Trademe.DownloadStringAsync(new Uri("http://api.trademe.co.nz/v1/Search/General.xml?search_string=" + listingId + ".xml"));
progressBar1.IsIndeterminate = true;
progressBar1.Visibility = Visibility.Visible;
}
}
void Trademe_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
return;
var r = XDocument.Parse(e.Result);
// Declare the namespace
XNamespace ns = "http://api.trademe.co.nz/v1";
ListingDetails.ItemsSource = from TM in r.Root.Descendants(ns + "Listing")
select new TradeItem
{
ImageSource = TM.Element(ns + "PictureHref").Value,
Title = TM.Element(ns + "Title").Value,
Region = TM.Element(ns + "Region").Value,
PriceDisplay = TM.Element(ns + "PriceDisplay").Value,
ListingId = TM.Element(ns + "ListingId").Value,
};
progressBar1.IsIndeterminate = false;
progressBar1.Visibility = Visibility.Collapsed;
}
public class TradeItem
{
public string Region { get; set; }
public string ListingId { get; set; }
public string PriceDisplay { get; set; }
public string Title { get; set; }
public string ImageSource { get; set; }
}
private void hyperlinkButton1_Click(object sender, RoutedEventArgs e)
{
NavigationService.GoBack();
}
private void button4_Click(object sender, RoutedEventArgs e)
{
}
}
}