Reputation: 9242
i am getting problem with the observablecollection because it is not updating my view. it is getting data in it i have checked it. i have also make event its collection changed event but it is also not getting called. i don't know why is this happening here is my code..
public async Task GetActivityStudentCollection()
{
StudentActivityCollection = await ViewModelLocator.ActivityViewModel.GetActivity(0, 8, 0, 20);
StudentActivityCollection.CollectionChanged += StudentActivityCollection_CollectionChanged;
// RaisePropertyChanged("StudentActivityCollection");
}
void StudentActivityCollection_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
// throw new NotImplementedException();
}
i have bind this collection with listview like this.
ActivityListViewSource.Source = ViewModelLocator.DashBoard.StudentActivityCollection;
this ViewModelLocator.ActivityViewModel.GetActivity(0, 8, 0, 20); method is returning a collection that is i have binded(not working) but if i binded the collection directly to the collection that is going to be return it works..means if i binded like this(it work)..
ActivityListViewSource.Source = ViewModelLocator.ActivityViewModel.ActivityCollection;
i am sorry for my bad english.please try to understand the problem. is it because of async method or what. any kind of help is appreciated..
Upvotes: 0
Views: 167
Reputation: 5201
Try something like this
public async Task GetActivityStudentCollection()
{
var studentActivityColl = await ViewModelLocator.ActivityViewModel.GetActivity(0, 8, 0, 20);
foreach(var studentAct in studentActivityColl)
StudentActivityCollection.Add(studentAct);
StudentActivityCollection.CollectionChanged += StudentActivityCollection_CollectionChanged;
// RaisePropertyChanged("StudentActivityCollection");
}
Upvotes: 1
Reputation: 22038
You shouldn't return a new collection from that method. You should pass an instance.
ObservableCollection studentActivityCollection = new ObservableCollection();
studentActivityCollection.CollectionChanged += StudentActivityCollection_CollectionChanged;
await ViewModelLocator.ActivityViewModel.GetActivity(studentActivityCollection, 0, 8, 0, 20);
Because all events are fired before you registered your event on it.
Upvotes: 0