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 1025113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:52:46+00:00 2026-05-16T11:52:46+00:00

MVVM pattern is implemented in my Silverlight4 application. Originally, I worked with ObservableCollection of

  • 0

MVVM pattern is implemented in my Silverlight4 application.

Originally, I worked with ObservableCollection of objects in my ViewModel:

public class SquadViewModel : ViewModelBase<ISquadModel>
{
    public SquadViewModel(...) : base(...)
    {
        SquadPlayers = new ObservableCollection<SquadPlayerViewModel>();
        ...
        _model.DataReceivedEvent += _model_DataReceivedEvent;
        _model.RequestData(...);
    }

    private void _model_DataReceivedEvent(ObservableCollection<TeamPlayerData> allReadyPlayers, ...)
    {
        foreach (TeamPlayerData tpd in allReadyPlayers)
        {
            SquadPlayerViewModel sp = new SquadPlayerViewModel(...);
            SquadPlayers.Add(sp);
        }
    }
    ...
}

Here is a peacie of XAML code for grid displaying:

xmlns:DataControls="clr-namespace:System.Windows.Controls;
                    assembly=System.Windows.Controls.Data"
...
<DataControls:DataGrid ItemsSource="{Binding SquadPlayers}">
    ...</DataControls:DataGrid>

and my ViewModel is bound to DataContext property of the view.

This collection (SquadPlayers) is not changed after its creation so I would like to change its type to

List<SquadPlayerViewModel>

. When I did that, I also added

RaisePropertyChanged("SquadPlayers")

in the end of ‘_model_DataReceivedEvent’ method (to notify the grid that list data are changed.

The problem is that on initial displaying grid doesn’t show any record… Only when I click on any column header it will do ‘sorting’ and display all items from the list…

Question1: Why datagrid doesn’t contain items initially?
Q2: How to make them displayed automatically?

Thanks.

P.S. Here is a declaration of the new List object in my view-model:

        public List<SquadPlayerViewModel> SquadPlayers { get; set; }
  • 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-05-16T11:52:47+00:00Added an answer on May 16, 2026 at 11:52 am

    You can’t use List as a binding source, because List not implement INotifyCollectionChanged it is require for WPF/Silverlight to have knowledge for whether the content of collection is change or not. WPF/Sivlerlight than can take further action.

    I don’t know why you need List<> on your view model, but If for abstraction reason you can use IList<> instead. but make sure you put instance of ObservableCollection<> on it, not the List<>. No matter what Type you used in your ViewModel Binding Only care about runtime type.

    so your code should like this:

    //Your declaration
    public IList<SquadPlayerViewModel> SquadPlayers { get; set; }
    //in your implementation for WPF/Silverlight you should do
    SquadPlayers = new ObservableCollection<SquadPlayerViewModel>();
    //but for other reason (for non WPF binding) you can do
    SquadPlayers = new List<SquadPlayerViewModel>();
    

    I usually used this approach to abstract my “Proxied” Domain Model that returned by NHibernate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.