Imports System.Xml.Linq
Partial Public Class MainPage
Inherits UserControl
Public Sub New()
InitializeComponent()
End Sub
Private Sub search_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Dim topic As String
Dim diggUrl As String
Dim diggService As WebClient
topic = research.Text
diggUrl = String.Format("http://services.digg.com/stories/topic/{0}?count=20&appkey=http%3A%2F%2Fscottgu.com", topic)
diggService = New WebClient()
' Specify that the DiggService_DownloadStoriesCompleted method gets called
' when the download completes.
AddHandler diggService.DownloadStringCompleted, AddressOf DiggService_DownloadStoriesCompleted
diggService.DownloadStringAsync(New Uri(diggUrl))
End Sub
Private Sub DiggService_DownloadStoriesCompleted(ByVal sender As System.Object, ByVal e As DownloadStringCompletedEventArgs)
Dim result As String
If (e.Error Is Nothing) Then
'result = e.Result
DisplayStories(e.Result)
'id.Text = result
Else
' id.Text = "error"
End If
End Sub
Private Sub DisplayStories(ByVal xmlContent As String)
Dim document As XDocument = XDocument.Parse(xmlContent)
Dim res = From story In document.Descendants("story") _
Select New Diggstory() With { _
.Id = (story.Attribute("id")), _
.Title = Convert.ToString(story.Element("title")), _
.Description = Convert.ToString(story.Element("description")).Trim(), _
.ThumbNail = (story.Element("thumbnail").Attribute("sr").Value)} _
'.HrefLink = (New Uri(story.Attribute("link").ToString)), _
' .NumDiggs = Val(story.Attribute("diggs")), _
' .UserName = story.Element("user").Attribute("name").Value.ToString _
id.Text = res.ToString
StoriesList.ItemsSource = res
End Sub
End Class
voici mon erreur:
"La référence d'objet n'est pas définie à une instance d'un objet."