views:

704

answers:

3

Im trying to create this:

Tag1 has the erdered list of objects O1, O3, O2 Tag2 has the erdered list of objects O1, O4

Every time I click a tag, I want to see the list of objects. So clicking Tag1 would show in a listbox:

O1

O3

O2

But I would like to keep the auto update so every time I edit or add/delete an object it auto updates (I suppose I need to implement something like the interfaces INotifyCollectionChanged and INotifyPropertyChanged).

I could use a database and have the tables Tag, Object and TagObject, this last one with the TagID and ObjectID. But I also would like to avoid databases, its a desktop application.

I could also use objects like ObservableCollections, but I have the problem of having duplicate objects. I can use references to the objects but it gets messy.

Anyone has any suggestion on how to do this?

Thank you

A: 

One option would be to create an object that contains a dataset (System.Data namespace). Inside the dataset it would have 3 tables that would be linked using defined foreign keys the same as if it was in a database. These can later be stored to XML if need be.

Your object would then have to expose a dataview which can be set as the datacontext and bound too.

Editing the dataset in code then updates the screen and editing the screen will update the dataset.

John
Thank you John. But the DataSet doesnt implement ICollectionChanged. Is the screen updated when I add a row to one table?
Artur Carvalho
Odd though it seems and even though it does not implement ICollectionChanged it does work. I guess this is because it is not a collection but an XML based object.
John
A: 

Im analysing Bindable LINQ. Lets see if this one does it.

Artur Carvalho
A: 

Move all the logic controlling the updated data out of the WPF page and into another class that pushes the new data into the WPF page, when it changes, rather than the WPF pulling the data out of the objects.

Here is some example code:

class WpfPage
{
   public List OrderedListForTag1 { set { /* whatever GUI binding code you need to deal with the new list for tag 1 */ }


   public List OrderedListForTag2 { set { /* whatever GUI binding code you need to deal with the new list for tag 2*/ }

}

class WpfPresenter
{
  WpfPage thePage;

  public void Tag1Selected()
  {
      //Calculate changes to 01, 02, 04 etcetce
      //If changed, update the page
      thePage.OrderedListForTag1 = //new list of objects
  }
}

This is one of the model-view-controller pattern(s) which is very common in GUI construction. This series of articles covers the concepts.

Jimmy McNulty