2012-02-15 8 views
0

私はxml解析を使用してデータを取得するアプリケーションを開発中です。インターネットでの検索がほとんど行われなくなり、最終的に私の必要性に合ったコードが見つかりました。ノートとして、私はMainPage.xaml.csxmlはこのようにしてMainViewModelで解析します

 try 
     { 
      if (e.Error != null) 
      { 
       MessageBox.Show(e.Error.ToString(), "Error", MessageBoxButton.OK); 
      } 

      XElement profiler = XElement.Parse(e.Result); 

      listBox2.ItemsSource = from developers in profiler.Descendants("status") 
            select new ItemViewModel 
            { 
             Tweet = developers.Element("text").Value, 
             TweetImage = developers.Element("user").Element("profile_image_url").Value, 
             TweetSender = developers.Element("user").Element("screen_name").Value, 
            }; 
     } 

     catch (Exception ex) 
     { 
      MessageBox.Show(ex.Message.ToString() + "\nThis may caused by your IP has made over 150 request in less than 1 hour. Try checking back in the next hour or try restarting your phone."); 
      return; 
     } 

でそれを置いたが、それは詳細ページに移動するとき、それは例外にtruned。 WebClientのダウンロード完了イベントハンドラのMainViewModelクラスにそのコードを配置します。このようにしてXML解析を行うためにはどの行を編集すればよいのですか?しかし、MainViewModelではどの行を編集すればよいですか?どんな答えでも分かるでしょう

ありがとうございます。

答えて

0

これをMainViewModelで実装したい場合は、最初にTeet、TweetImageなどを含むモデルクラスを作成する必要があります。次に、解析結果を「List/Observable」コレクションに配置し、それをバインドする必要がありますあなたのリストボックスにxamlを通して収集する。これにより、問題が解決されます。

+0

私はファイルを作成しました。今、私は何を編集すべきですか? – user1072976

+0

この行で何を変更する必要がありますか? listBox2.ItemsSource = profiler.Descendants( "status") – user1072976

+0

の開発者から、List ParsedList ..を与える必要があるlistBox2.ItemsSourceではなく、この解析リストをurにバインドする必要がありますUI –

関連する問題