views:

9

answers:

0

I am trying to buid a forum in silverlight.

I am using RIA services, EF4 and silverlight 4.

I have a datagrid with topics. When the row is clicked on, the threads for that topic are added to a listbox. Everything is working correctly with one exception: When a new thread is added, the listbox does not update its contents unless I click another topic and then click back to the topic that has just had a new thread added.

I guessed this might be because the collection (ForumThreads) that the list box is being bound to did not implement the ObservableCollection interface. I have now added a list implementing ObservableCollection but still no refresh happens: Here is the code....

 public void LoadForumThreads(int forumTopicID)
    {
        ObservableCollection<ForumThread> threads = new ObservableCollection<ForumThread>();

        var query = this.ctx.GetForumThreadsQuery(forumTopicID);
        var loadOperation = this.ctx.Load(query);
        loadOperation.Completed += (sender, e) =>
            {
                if (!loadOperation.HasError)
                {
                    foreach (ForumThread item in loadOperation.Entities)
                    {
                        threads.Add(item);
                    }
                    this.lstThreads.DataContext = threads.FirstOrDefault();
                    this.lstThreads.ItemsSource = threads;
                }
            };
    }