Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7929719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:10:52+00:00 2026-06-03T20:10:52+00:00

I am playing around with creating a Windows Phone application. I have been watching

  • 0

I am playing around with creating a Windows Phone application. I have been watching this tutorial, but I am having some issues that the view is not updated with the data (the template is simply empty).

I have made sure that the items collection is actually set with data, but I suspect that it is the NotifyPropertyChanged event which is not fired correctly.

What might I be missing?

My MainViewModel looks like this:

public class MainViewModel : INotifyPropertyChanged
{
    private ServiceAgent _serviceAgent;
    public MainViewModel()
    {
        this.Items = new ObservableCollection<SocialListItemViewModel>();
        if (_serviceAgent == null)
        {
            _serviceAgent = new ServiceAgent();
        }
    }

    /// <summary>
    /// A collection for ItemViewModel objects.
    /// </summary>
    public ObservableCollection<SocialListItemViewModel> Items { get; private set; }

    public bool IsDataLoaded
    {
        get;
        private set;
    }

    /// <summary>
    /// Creates and adds a few ItemViewModel objects into the Items collection.
    /// </summary>
    public void LoadData()
    {
        _serviceAgent.GetSocialItems();
        _serviceAgent.SocialItemsLoaded += new ServiceAgent.SocialListItemsLoadedEventHandler(_serviceAgent_SocialItemsLoaded);

        //// Sample data; replace with real data
        //this.Items.Add(new SocialListItemViewModel() { ContentShort = "Facilisi faucibus habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis senectus sociosqu", ImageUrl = "http://profile.ak.fbcdn.net/hprofile-ak-ash2/50215_277666338969761_534345200_t.jpg" });
        //this.Items.Add(new SocialListItemViewModel() { ContentShort = "Habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis senectus sociosqu suscipit torquent", ImageUrl = "http://profile.ak.fbcdn.net/hprofile-ak-ash2/50215_277666338969761_534345200_t.jpg" });
        //this.Items.Add(new SocialListItemViewModel() { ContentShort = "Ultrices vehicula volutpat maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus habitant inceptos", ImageUrl = "http://profile.ak.fbcdn.net/hprofile-ak-ash2/50215_277666338969761_534345200_t.jpg" });
        //this.Items.Add(new SocialListItemViewModel() { ContentShort = "Maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus habitant inceptos interdum lobortis nascetur", ImageUrl = "http://profile.ak.fbcdn.net/hprofile-ak-ash2/50215_277666338969761_534345200_t.jpg" });

        this.IsDataLoaded = true;
    }

    void _serviceAgent_SocialItemsLoaded(ObservableCollection<SocialListItemViewModel> socialItems)
    {
        Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                      {

                                                          this.Items = socialItems;

                                                          //this.Items.Add(new SocialListItemViewModel() { ContentShort = "Facilisi faucibus habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis senectus sociosqu", ImageUrl = "http://profile.ak.fbcdn.net/hprofile-ak-ash2/50215_277666338969761_534345200_t.jpg" });
                                                          //this.Items.Add(new SocialListItemViewModel() { ContentShort = "Habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis senectus sociosqu suscipit torquent", ImageUrl = "http://profile.ak.fbcdn.net/hprofile-ak-ash2/50215_277666338969761_534345200_t.jpg" });
                                                          //this.Items.Add(new SocialListItemViewModel() { ContentShort = "Ultrices vehicula volutpat maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus habitant inceptos", ImageUrl = "http://profile.ak.fbcdn.net/hprofile-ak-ash2/50215_277666338969761_534345200_t.jpg" });
                                                          //this.Items.Add(new SocialListItemViewModel() { ContentShort = "Maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus habitant inceptos interdum lobortis nascetur", ImageUrl = "http://profile.ak.fbcdn.net/hprofile-ak-ash2/50215_277666338969761_534345200_t.jpg" });
                                                          NotifyPropertyChanged("ContentShort");
                                                      });
    }

    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(String propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (null != handler)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

The view model looks like this:

[DataContract]
public class SocialListItemViewModel : INotifyPropertyChanged
{

    private string _contentshort;
    /// <summary>
    /// Sample ViewModel property; this property is used in the view to display its value using a Binding.
    /// </summary>
    /// <returns></returns>
    [DataMember]
    public string ContentShort
    {
        get
        {
            return _contentshort;
        }
        set
        {
            if (value != _contentshort)
            {
                _contentshort = value;
                NotifyPropertyChanged("ContentShort");
            }
        }
    }

    private string _imageUrl;
    /// <summary>
    /// Sample ViewModel property; this property is used in the view to display its value using a Binding.
    /// </summary>
    /// <returns></returns>
    [DataMember]
    public string ImageUrl
    {
        get
        {
            return _imageUrl;
        }
        set
        {
            if (value != _imageUrl)
            {
                _imageUrl = value;
                NotifyPropertyChanged("ImageUrl");
            }
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(String propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (null != handler)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

The service agent, which extracts the data looks like this:

public class ServiceAgent
{
    public delegate void SocialListItemsLoadedEventHandler(ObservableCollection<SocialListItemViewModel> socialItems);
    public event SocialListItemsLoadedEventHandler SocialItemsLoaded;

    private ObservableCollection<SocialListItemViewModel> socialListItemViewModels = new ObservableCollection<SocialListItemViewModel>();
    public void GetSocialItems()
    {
        WebClient wcNewsTractor = new WebClient();
        wcNewsTractor.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wcNewsTractor_DownloadStringCompleted);
        wcNewsTractor.DownloadStringAsync(new Uri("URL TO JSON FEED"));

    }

    void wcNewsTractor_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        if (e.Error == null && e.Cancelled == false)
        {
            //ObservableCollection<SocialListItemViewModel> socialListItemViewModels = new ObservableCollection<SocialListItemViewModel>();

            ThreadPool.QueueUserWorkItem((s) =>
            {
            socialListItemViewModels = ReadToObject(e.Result);
            Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                          {
                                                              SocialItemsLoaded(socialListItemViewModels);
                                                          });

            });

        }
    }

    // Deserialize a JSON stream to a User object.
    public static ObservableCollection<SocialListItemViewModel> ReadToObject(string json)
    {
        ObservableCollection<SocialListItemViewModel> res = new ObservableCollection<SocialListItemViewModel>();
        List<SocialListItemViewModel> deserializedItems = new List<SocialListItemViewModel>();
        MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json));
        DataContractJsonSerializer ser = new DataContractJsonSerializer(deserializedItems.GetType());
        deserializedItems = ser.ReadObject(ms) as List<SocialListItemViewModel>;
        ms.Close();
        return new ObservableCollection<SocialListItemViewModel>(deserializedItems);
    }
}

In my MainPage the constructor looks like this:

public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Set the data context of the listbox control to the sample data
            DataContext = new SocialListItemViewModel(); //App.ViewModel;
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

The MainPage.xaml where the template is added looks like this:

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <ListBox x:Name="MainListBox" Margin="0,0,-12,0" ItemsSource="{Binding Items}" SelectionChanged="MainListBox_SelectionChanged" ItemContainerStyle="{StaticResource ListBoxItemStyle1}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                  <StackPanel Margin="0,0,0,17" Width="432" Height="225" d:DataContext="{d:DesignData /SampleData/SocialListItemViewModelSampleData1.xaml}">
                      <Image  Height="125" Width="125" Margin="0" Source="http://myimage.com/myimage.jpg" HorizontalAlignment="Left" VerticalAlignment="Center"/>
                      <TextBlock x:Name="ContentShort" Text="{Binding ContentShort}" TextWrapping="Wrap" Margin="0,-125,0,0" Style="{StaticResource PhoneTextSubtleStyle}" HorizontalAlignment="Right" Foreground="#99FFFFFF" Width="279" RenderTransformOrigin="0.459,0.513" VerticalAlignment="Center" Height="160"/>
                      <Button Name="btnVote" Height="72" HorizontalAlignment="Center" Width="225" Margin="0,-10,-130,0" VerticalAlignment="Center" BorderThickness="2" Content="Vote" Background="#FF0090A1" />
                  </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:10:53+00:00Added an answer on June 3, 2026 at 8:10 pm

    Ok, what I think is probably going on here is that you aren’t firing your notify for the ObservableCollection Items.

    In this line:

     Deployment.Current.Dispatcher.BeginInvoke(() =>
                           {
                               this.Items = socialItems;
    

    You are throwing out your old ObservableCollection, and assigning it to the one being returned from your service. The ObservableCollection only sends out notifications on adds/deletes, so when you do this, nothing is getting fired to the view.

    You have two ways of fixing this. One is to set up Items with a private backing member variable, and calling NotifyPropertyChanged("Items") in the setter. Alternatively, you can return a generic List<>, and iterate through the contents, adding them to the Items collection, something like this:

     Deployment.Current.Dispatcher.BeginInvoke(() =>
                           {
                               this.Items.Clear();
                               foreach(var item in socialItems)
                               {
                                    this.Items.Add(item);
                               }
                           }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been playing around with creating an application using the S#arp Architecture . One
I've been playing around with creating a new user and I keep getting this
I have started playing around with Berkeley DB. This one is really interesting, but
I am playing around creating a demo prism application. The application I have has
I've been playing around with creating a REST based WCF service sending and receiving
I've been playing around with creating an e-commerce site with Codeigniter, and am trying
I have been working with C++ and Win32 (non MFC/ATL) I am playing around
I've been playing around with Inno Setup for a couple days now, and have
I've been playing around with Active Record a bit, and I have noticed that
I am playing around with Object Oriented Design/Database design by creating an application that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.