0

こんにちは、私はWindows Phone用のアプリケーションを開発しています.Webからxmlを読みたいので、ページロードイベントで使用しています:

Dim cl As New WebClient AddHandler cl.DownloadStringCompleted, AddressOf cl_DownloadStringCompleted cl.DownloadStringAsync(New Uri("demo.com/1.xml",UriKind.RelativeOrAbsolute))

そしてcl.DownloadStringCompletedイベントで:

Dim doc = XDocument.Load("demo.com/1.xml")

しかし、何らかの理由で私はクラッシュします! バグは、URI「demo.com/1.xml」を使用する必要がないことですが、他のいくつか:S

4

1 に答える 1

1

DownloadStringCompletedイベントにはDownloadStringCompletedEventArgs. これらの引数の Result プロパティを使用する必要があります。

Dim client As New WebClient()
AddHandler client.DownloadStringCompleted, AddressOf ClientOnDownloadStringCompleted
client.DownloadStringAsync(New Uri("http://demo.com/xml"))

およびハンドラー:

Private Sub ClientOnDownloadStringCompleted(sender As Object, args As DownloadStringCompletedEventArgs)
    Dim doc = XDocument.Parse(args.Result)
End Sub
于 2012-05-10T20:44:57.017 に答える