私はWindows Phone 7アプリケーション全体を構築しました(私はかなり誇りに思っています!)しかし、私のアプリでアクセスされたXMLファイルが私のウェブサイト。彼らは本当に更新する必要がないので、私は単にプロジェクトの一部として含めるほうがはるかに意味があると判断しました。しかし、私が学んだ私の経験やチュートリアルのほとんどは、WebClientを通してXMLデータをダウンロードした後にリストボックスにXMLデータを解析する方法を示しています。では、WebClientをオフラインXMLローダーに置き換える簡単な方法はありますか?WebClientをオフラインXDocumentに置き換える
これは基本的に私のアプリケーションのいくつのページがコード化されているのかわかりませんが、わかりやすくするために私のアプリの目的に固有の名前を人/名前/年齢についてナンセンスに変更しました。
namespace WindowsPhoneApplication14.Pages.Other
{
public partial class People : PhoneApplicationPage
{
public People()
{
InitializeComponent();
Dispatcher.BeginInvoke((Action)(() => pplListBox.ItemsSource = ppldata));
WebClient pplWebClient = new WebClient();
pplWebClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(ppl_DownloadStringCompleted);
pplWebClient.DownloadStringAsync(new Uri("http://www.mywebsite.com/ppl.xml"));
}
void ppl_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
return;
XElement xmlitem = XElement.Parse(e.Result);
var ppldata = new List<PeopleClass>();
foreach (XElement item in xmlitem.Elements("entry"))
{
var name = item.Element("name");
var namevalue = (name == null) ? null : name.Value;
var age = item.Element("age");
var agevalue = (age == null) ? null : age.Value;
ppldata.Add
(new PeopleClass
{
Name = namevalue,
Age = agevalue,
}
);
}
pplListBox.ItemsSource = ppldata;
}
public class PeopleClass
{
public string Name { get; set; }
public string Age { get; set; }
}
public System.Collections.IEnumerable ppldata { get; set; }
}
}
WebClient操作をどのように交換できますか?
おかげで再び、ミックは。私はすぐに私ができるようにこれを試してみましょう。 – Dan
YW :) ../15char –