1

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.

H.B.
  • 166,899
  • 29
  • 327
  • 400
Edward Leno
  • 6,257
  • 3
  • 33
  • 49
  • Just curious: if speed is not an issue, why a LinkedList and not an `ObservableCollection`? – Emond Jan 27 '12 at 21:03
  • I have taken your advice and switched to an ObservableCollection, and so far, so good. As I mentioned in a comment below, if I later need the performance and/or speed of the LinkedList solution, I will switch back. Thanks! – Edward Leno Feb 07 '12 at 13:27
  • Nice to hear that it's working but it wasn't advice; it was a question... – Emond Feb 07 '12 at 13:42

1 Answers1

4
  • 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();
Luke Woodward
  • 63,336
  • 16
  • 89
  • 104
Muhammad Hasan Khan
  • 34,648
  • 16
  • 88
  • 131
  • +1: implementing a LinkedList that also implements INotifyCollectionChanged was how I was thinking of doing this one too. – Luke Woodward Jan 27 '12 at 20:59
  • This is what I was looking for (took a while to learn/implement). Thanks! BTW, though this works, I am going to simplify my solution to use the ObservableCollecton that Erno suggested and switch to this if performance and/or functionality becomes an issue. – Edward Leno Feb 07 '12 at 13:26