【发布时间】:2012-02-14 13:56:10
【问题描述】:
所以,我正在为 wp7 制作一个应用程序。 为简单起见,这些是我的文件:
- LoginPage.xaml(启动页面)
- MainPage.xaml
- MainViewModel.cs
- ItemViewModel.cs
在 MainViewModel.cs 中,我包含了以下函数:
private void DownloadItems()
{
string key = this.User.Key;
WebClient wc = new WebClient();
wc.DownloadStringCompleted += callback;
wc.DownloadStringAsync(new Uri("http://localhost/items?key=" + key)); //JSON
}
以及回调函数:
private void callback(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
List<ItemViewModel> col = Deserialize_ItemViewModel(e.Result); // deserialize JSON to List<ItemViewModel>
this.Items = new ObservableCollection<ItemViewModel>(col);
ItemDB.Sponsors.InsertAllOnSubmit(col);
ItemDB.SubmitChanges();
this.IsDataLoaded = true;
// ???
}
}
当用户登录时,登录将被处理,当一切正常时,将使用新设置的 User.Key 调用 DownloadItems。
我需要在下载过程中显示 ProgressIndicator,当下载完成并处理完毕后,我想导航到 MainPage.xaml,届时它将准备就绪。
希望有人能帮助我,在此先感谢!
【问题讨论】:
标签: c# silverlight windows-phone-7 mvvm viewmodel