2012-05-10 66 views
0

Windows Phone的你好我正在開發的應用程序,我想,所以我使用的頁面加載事件從網絡 讀取XML:VB的Silverlight for Windows Phone支持 「DownloadStringAsync」

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

回答

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 
+0

是'args.Result'從請求字符串的內容或者是它的文件名?如果它是一個包含xml的字符串,那麼你會想調用'XDocument.Parse'而不是'Load'。 – CoderDennis

+0

非常感謝你! 它的工作! –

+0

是!謝謝丹尼斯! –

相關問題