Data Binding to a LinkedList?

2k views Asked by At

What Works:

  • Web service that manipulates an in-memory LinkedList (of strings).
  • Clients can insert/add/remove/query the contents of the LinkedList.
  • Web service is started from the command line (no UI).

What I Would Like to Do:

  • Change the command line app to a WPF app.
  • From the WPF app display the current state of the LinkedList.
  • Data bind the UI control so any client actions are reflected in the display.

Speed is not a huge issue, as the WPF app is read-only and more informational. I chose a LinkedList to support the needed client functionality.

I am having difficulty finding any tutorials and/or examples that can help. Any suggestions on how I should approach this would be great.

1

There are 1 answers

2
Muhammad Hasan Khan On BEST ANSWER
  • Create a new class called ObservableLinkedList and implement INotifyCollectionChanged.
  • Give same methods in that class as LinkedList and internally forward all the methods to the contained linkedlist,
  • but also fire INotifyCollectionChanged events so WPF can know that your linked list changed.

For WPF to know that a bound collection has changed; it has to implement INotifyCollectionChanged

OR

Just trigger collectionview to be refreshed everytime you update the linkedlist like the following

CollectionViewSource.GetDefaultView(ViewModel.TheCollectionProperty).Refresh();