views:

33

answers:

1

Hi, i am working on application in WP7 , i would like to pass a list box as parameter to client_DownloadStringCompleted method.

My code looks like below ,

WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
+1  A: 

Just add this line to your code:

client.DownloadStringAsync(yourUri, yourListBox);
Gabriel McAdams
How will i access this listbox in the method ?
sachin saner
The listbox will be in the `UserState` property of the `DownloadStringCompletedEventArgs` passed to the event handler. Youo can get it with: `ListBox lb = (ListBox)e.UserState;`
Jim Mischel
Worked like a charm ! Thank you guys ! Also i wanted to know that what if i want to pass more than one parameter to this event handler ?
sachin saner
The UserState is of type `Object`. That means you can pass anything you want into it. If you need more than one thing passed in, then pass in an object array: `object[] { param1, param2 }`
Gabriel McAdams