views:

32

answers:

1

I have the following scenario:

  1. User enters values in a form and submits
  2. The submit methods calls a service passing the form related object as a parameter
  3. The object is persisted in the db
  4. The object gets assigned a new ID and gets returned to the calling method
  5. The object is add to a collection in the submit method

I have an expander control that is bound to the collection using an item list and inside each list is a sub list.

What is the best practice for refreshing the view to show the updated object. What I was doing to refresh the collection was the following:

             ObservableCollection<ProjectDto> projects = new ObservableCollection<ProjectDto>();
                Projects.ForEach(projects.Add);
                Projects.Clear();
                projects.ForEach(Projects.Add); 

This makes the expander collapse as I think it is being bound to a new collection.

A: 

Hi Burt

What is the relationship between projects (little p) and Projects (capital P) - why two lists? What does your binding look like?

EDIT

Let's assume for discussion that Projects is an ObservableCollection, and is what is bound to your UI, and that projects is either a temporary, domain model, or backend list that you use to assemble and prepare (sort, validate, etc.) DTOs for presentation. In this case, projects can just be a List, and you can every time you do Projects = new ObservableCollection(projects) your bound UI items collection should refresh.

Berryl

Berryl
I would set Projects = projects at the end so the Observable collection would update. The binding just binds to Projects.
Burt
see my edit above and try Projects = new ObservableCollection(projects) instead. If that doesn't work and my guess about what your doing is wrong let me know. HTH
Berryl