2011-10-24 65 views
0

我想顯示一個朋友列表,當我選擇一個朋友時,我的應用將導航到另一個頁面,顯示與此朋友相關的這些信息。 我試圖讀取使用Web服務的數據,並顯示它的一些(名稱和照片)在一個昂貴的lisBox,並將一些(id)臨時存儲在列表或集合中,我可以調用它並在我的url中使用它:與WP7的網絡服務和數據綁定

NavigationService.Navigate(new Uri("/MyApp;component/FriendDetails.xaml?id{0}",friend_id, UriKind.Relative)); 

回答

0

使用WebService查詢API,你需要在回調使用LINQ添加一個「下載回調」的查詢結果寫入對象的觀察集合你從想要的數據匹配結果。

這樣子。

friends = new ObservableCollection<Friend>(); 
    WebClient wc = new WebClient(); 
    wc.OpenReadCompleted += Feed; 
    wc.OpenReadAsync(new Uri(friendsURL)); 
} 

private void Feed(object Sender, OpenReadCompletedEventArgs e) 
{ 
    if (e.Error != null){ 
     return; 
    } 

    using (Stream s = e.result){ 

     XDocument doc = XDocument.Load(s); 

然後使用Linq循環訪問數據並添加您的observablecollection的朋友。

+0

請給我解釋一下例子:) – MarTech

+0

爲方便您編輯 –

+0

thx;)@Joseph Le Brech – MarTech