Search code examples
silverlightwindows-phone-7twitteroverloading

Error with WP7 Silverlight - No Overload for "" Matches Delegate


I am new to WP7 programming and I have been following this tutorial

http://weblogs.asp.net/scottgu/archive/2010/03/18/building-a-windows-phone-7-twitter-application-using-silverlight.aspx

However I have run into a number of errors and I was wondering if anyone could tell me why. I have been over and over the code and as far as I can see it is all correct.

The first issue is a:

No overload for "twitter_DownloadsStringCompleted" matches delegate system.net.downloadStringEventHandler

Here is the code:

private void button2_Click(object sender, RoutedEventArgs e)
{
    WebClient twitter = new WebClient();

    twitter.DownloadStringCompleted += new DownloadStringCompletedEventHandler(twitter_DownloadStringCompleted);
    twitter.DownloadStringAsync(new Uri("http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=" + username.Text));
}

void twitter_DownloadStringCompleted(object sender, DownloadStringCompletedEventHandler e)
{
    throw new NotImplementedException();
}

public class TwitterItem
{
    public string UserName { get; set; }
    public string Message { get; set; }
    public string ImageSource { get; set; }
}

void twitter_DownloadStringCompleted(object sender, DownloadStringCompletedEventHandler e)
{
    if (e.Error != null)
        return;
    XElement xmlTweets = XElement.Parse(e.Result);

    listBox1.ItemsSource = from tweet in xmlTweets.Descendants("status")
                           select new TwitterItem
                           {
                               ImageSource = tweet.Elemend("user").Element("profile_image_url").Value,
                               Message = tweet.Element("text").Value,
                               UserName = tweet.Element("user").Element("SCreen_name").Value
                           };
        }
    }
}

Solution

  • The argument list for your completed event handler should be:

    void twitter_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    

    note it's DownloadStringCompletedEventArgs not DownloadStringCompletedEventHandler.

    See this image from the tutorial:

    screen shot from tutorial