Imports System.Runtime.Serialization
Imports System.Collections.ObjectModel
Imports System.IO
Imports System.Text
Imports System.Xml.Linq
Partial Public Class MainPage
Inherits PhoneApplicationPage
' Constructor
Public Sub New()
InitializeComponent()
AddHandler Loaded, AddressOf MainPage_Loaded
End Sub
Dim client As WebClient
Dim prog As ProgressIndicator
Private Sub MainPage_Loaded(sender As Object, e As System.Windows.RoutedEventArgs)
Dim url As String = "http://localhost/myphp/getXML.php"
Dim uri As New Uri(url)
client = New WebClient()
client.AllowReadStreamBuffering = True
AddHandler client.DownloadStringCompleted, AddressOf client_DownloadStringCompleted
AddHandler client.DownloadProgressChanged, AddressOf client_DownloadProgressChanged
client.DownloadStringAsync(uri)
'*** SystemTray ProgressBar ***'
prog = New ProgressIndicator()
prog.IsVisible = True
prog.IsIndeterminate = True
prog.Text = "Downloading...."
SystemTray.SetProgressIndicator(Me, prog)
End Sub
Private Sub client_DownloadStringCompleted(sender As Object, e As DownloadStringCompletedEventArgs)
If e.Cancelled = False AndAlso e.Error Is Nothing Then
Dim myCustomer As New List(Of Customer)
Dim loadData As XDocument = XDocument.Parse(e.Result)
Dim data = From query In loadData.Descendants("customer")
Select New Customer With { _
.CustomerID = query.Element("CustomerID"), _
.Name = query.Element("Name"), _
.Email = query.Element("Email"), _
.CountryCode = query.Element("CountryCode"), _
.Budget = query.Element("Budget"), _
.Used = query.Element("Used")
}
Me.CustomerList.ItemsSource = data
prog.IsVisible = False
End If
End Sub
Private Sub client_DownloadProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs)
End Sub
<DataContract()> _
Public Class Customer
Sub New()
' TODO: Complete member initialization
End Sub
<DataMember()> _
Public Property CustomerID() As String
Get
Return m_CustomerID
End Get
Set(value As String)
m_CustomerID = value
End Set
End Property
<DataMember()> _
Public Property Name() As String
Get
Return m_Name
End Get
Set(value As String)
m_Name = value
End Set
End Property
<DataMember()> _
Public Property Email() As String
Get
Return m_Email
End Get
Set(value As String)
m_Email = value
End Set
End Property
<DataMember()> _
Public Property CountryCode() As String
Get
Return m_CountryCode
End Get
Set(value As String)
m_CountryCode = value
End Set
End Property
<DataMember()> _
Public Property Budget() As String
Get
Return m_Budget
End Get
Set(value As String)
m_Budget = value
End Set
End Property
<DataMember()> _
Public Property Used() As String
Get
Return m_Used
End Get
Set(value As String)
m_Used = value
End Set
End Property
Private m_CustomerID As String
Private m_Name As String
Private m_Email As String
Private m_CountryCode As String
Private m_Budget As String
Private m_Used As String
Public Sub New(ByVal strCustomerID As String,
ByVal strName As String,
ByVal strEmail As String,
ByVal strCountryCode As String,
ByVal strBudget As String,
ByVal strUsed As String)
Me.CustomerID = strCustomerID
Me.Name = strName
Me.Email = strEmail
Me.CountryCode = strCountryCode
Me.Budget = strBudget
Me.Used = strUsed
End Sub
End Class
End Class
อันนี้เป็นของ Windows Phone แต่มันใช้ Library ของ .NET เช่นเดียวกันครับ