我想知道如何将Windows Azure中的MobileServiceCollection插入到JSON Web服务的ObservableCollection中
private ObservableCollection<AddressDetail> _hereRestAddressDetail = null;
public ObservableCollection<AddressDetail> hereRestAddressDetail
{
get { return _hereRestAddressDetail; }
set { this.SetProperty(ref this._hereRestAddressDetail, value); }
}
private async void UpdateTransportDetail()
{
try
{
WebClient client = new WebClient();
client.DownloadStringCompleted += (s, e) =>
{
if (e.Error == null)
{
RootObjectDetail result = JsonConvert.DeserializeObject<RootObjectDetail>(e.Result);
hereRestAddressDetail.Clear();
hereRestAddressDetail.Insert(0,result);
}
else
{
isFailed = Visibility.Visible;
isFailedMessage = "Can't get data from web server, please refresh and make sure your internet data connected";
}
};
client.DownloadStringAsync(new Uri(hrefText + transportDetailURL));
hereRestAddressDetail = await addressTable.ToCollectionAsync();
}
catch (Exception)
{
isFailed = Visibility.Visible;
isFailedMessage = "Something wrong happen, please refresh";
}
}
我尝试做的是将我的azure数据添加到hereRestAddressDetail的下一个条目中(因为第一个来自json web服务),这个
hereRestAddressDetail = await addressTable.ToCollectionAsync();
但它只是替换了json中没有添加它的数据,我怎样才能让它与我的json数据一起出现呢?
答案 0 :(得分:0)
不确定问题是否仍然存在,但您可以替换while集合
hereRestAddressDetail = new ObservableCollection<AddressDetail>(await addressTable.ToCollectionAsync());
或者(我推荐这种方式)抓取OptimizedObservableCollection(例如,这里:http://www.pedrolamas.com/2013/05/08/cimbalino-windows-phone-toolkit-updated-to-v2-3-0/)并像
一样使用它hereRestAddressDetail.ReplaceWith(await addressTable.ToCollectionAsync()); // replace
or
hereRestAddressDetail.AddRange(await addressTable.ToCollectionAsync()); // add