简体   繁体   中英

Windows Phone 8 Binding

I have a Windows Phone 8 Pivot application which contains the auto generated MainViewModel Binding mechanism.

I have changed the MainViewModel class to suit my needs and changed the MainPage.xaml markup so that it binds to the correct properties.

All good.

Now - I have a class which calls a Web Service and a call-back method which fires when data is received:

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. The MainViewModel 's properties have private setters :

public ObservableCollection<SignViewModel> Signs { get; private set; }
public ObservableCollection<TweetsViewModel> Tweets { get; private set; }

Each of these objects have a NotifyPropertyChange event.

So how do I populate the Signs and Tweets objects and make the whole binding work automatically when retrieving data from a Web Service? How do I make the UI/Mainpage.xaml communicate with the Web Service Class and the MainViewModel class?

To solve the issue, I simply changed the setters to public for Signs and Tweets . Once this was in place, the NotifyPropertyChange worked it's magic and automatically bound to the View. Magic! I wonder why Microsoft Developers made the setters private .....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM