I'm parsing data from an xml file using WebClient. In DownloadStringCompleted method I have a string, which is parsed, that I want to pass into a click event handler. I want the click event to open my app's Marketplace details. For that I need a that parsed string which is a GUID and place it in the event handler. I tried to google it and found nothing. I just can't figure out how to do it.
Any help will be highly appreciated. Thanks!
Here's the code:
public void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
XDocument moreApps = XDocument.Parse(e.Result);
morePageAppList.ItemsSource = from Apps in moreApps.Descendants("App")
select new MoreApps
{
MoreImage = Apps.Element("link").Value,
Price = Apps.Element("price").Value,
Title = Apps.Element("title").Value
};
var link = (from Apps in moreApps.Descendants("App")
select new MoreApps
{
AppUri = (string)Apps.Element("marketplace").Value
}).Single();
string appLink = link.AppUri;
}
private void App_Name_Click(object sender, RoutedEventArgs e)
{
MarketplaceDetailTask marketplaceDetailTask = new MarketplaceDetailTask();
marketplaceDetailTask.ContentIdentifier = "Marketplace GUID";
marketplaceDetailTask.Show();
}
UPDATED CODE:
morePageAppList.ItemsSource = from Apps in moreApps.Descendants("App")
select new MoreApps
{
MoreImage = Apps.Element("link").Value,
Price = Apps.Element("price").Value,
Title = Apps.Element("title").Value
};
var link = (from Apps in moreApps.Descendants("App")
select new MoreApps
{
AppUri = (string)Apps.Element("marketplace").Value
}).FirstOrDefault();
appLink = link.AppUri;
}
private void App_Name_Click(object sender, RoutedEventArgs e)
{
ShowMarket(appLink);
}
private void ShowMarket(string id)
{
MarketplaceDetailTask marketplaceDetailTask = new MarketplaceDetailTask();
marketplaceDetailTask.ContentIdentifier = id;
marketplaceDetailTask.Show();
}
Simply move your desired functionality out of the click handler and add a parameter. That way, you can just call the method and pass in the value
ShowMarket(link.AppUri)
edit: in response to a comment clarifying the question ... all you'd need to do is set link.AppUri to a class property or field, and then in the click handler, simply use that variable to pass to ShowMarket (or however you choose to express the functionality, even right in the click handler)
As I see it there are two ways of doing what you want.
1) Make a class wide variable, aka a field. This can be seen and modified in any of the classes methods. It is a shared variable between the classes methods.
2) Try calling the App_Name_Click method directly passing the variable you want as an object in the sender parameter. ie
App_Name_Click(appLink, new RoutedEventArgs())
or a tidier way is to do this:App_Name_Click(this, new MyRoutedEventArgs(){GUID = appLink})