[英]Windows Phone 8 Binding
I have a Windows Phone 8 Pivot application which contains the auto generated MainViewModel
Binding mechanism. 我有一个Windows Phone 8 Pivot应用程序,其中包含自动生成的MainViewModel
绑定机制。
I have changed the MainViewModel
class to suit my needs and changed the MainPage.xaml
markup so that it binds to the correct properties. 我已经更改了MainViewModel
类以满足我的需要,并更改了MainPage.xaml
标记,以便将其绑定到正确的属性。
All good. 都好。
Now - I have a class which calls a Web Service and a call-back method which fires when data is received: 现在-我有一个调用Web服务的类和一个在接收到数据时触发的回调方法:
private void GetSigns_Completed(object sender, OpenReadCompletedEventArgs e)
{
using (var sr = new StreamReader(e.Result))
{
var data = sr.ReadToEnd();
var result = JsonConvert.DeserializeObject<SignViewModel>(data);
}
}
As you can see, I am not returning or populating anything with the result
object as I do not know how to do so. 如您所见, result
不知道如何返回result
对象,所以我没有返回或填充任何东西。 The MainViewModel
's properties have private setters
: MainViewModel
的属性具有私有setters
:
public ObservableCollection<SignViewModel> Signs { get; private set; }
public ObservableCollection<TweetsViewModel> Tweets { get; private set; }
Each of these objects have a NotifyPropertyChange
event. 这些对象中的每个对象都有一个NotifyPropertyChange
事件。
So how do I populate the Signs
and Tweets
objects and make the whole binding work automatically when retrieving data from a Web Service? 那么,当从Web服务检索数据时,如何填充Signs
and Tweets
对象并自动使整个绑定起作用? How do I make the UI/Mainpage.xaml
communicate with the Web Service Class and the MainViewModel
class? 如何使UI/Mainpage.xaml
与Web服务类和MainViewModel
类通信?
To solve the issue, I simply changed the setters
to public for Signs
and Tweets
. 为了解决该问题,我只是将setters
更改为公开的“ Signs
and Tweets
。 Once this was in place, the NotifyPropertyChange
worked it's magic and automatically bound to the View. 一旦安装到位, NotifyPropertyChange
了魔力,并自动绑定到视图。 Magic! 魔法! I wonder why Microsoft Developers made the setters private ..... 我不知道为什么Microsoft开发人员将二传手设为私人.....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.