"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!
LinkedList isn't designed for inheritance: most of its methods are not virtual, so there is nothing to override. If you want to reuse its implementation and implement INotifyCollectionChanged, use composition, not inheritance. But anyway, it wouldn't make sense to implement an observable linked list, because a linked list doesn't support random access by index, and CollectionChanged notifications are only useful if you specify an index (unless you only raise NotifyCollectionChangedAction.
Reset notifications, but then it's not very efficient).
NotifyCollectionChangedAction. Reset does do the deed, and anyway it's highly unlikely that I get more than 20 segments. Any other downside?
I'm actually thinking of just calling OnNotifyCollectionChanged(NotifyCollectionChangedAction. Reset) on the CollectionChanged event that I'd subscribe to. – Baboon Aug 9 at 13:15 I can't think of any other downside... as long as the collection is small, it shouldn't have a major impact of performance – Thomas Levesque Aug 9 at 13:36.
It is a good solution, you'll just have to create your own implementation of a LinkedList. LinkedList does not implement any linky listy interface, so you are on your own as to the methods/properties. I suppose a good guide would be to duplicate the public methods and properties of LinkedList.
This would allow you to use an actual instance of the collection as your backing store.
I'd just like not to have to manually call OnNotifyCollectionChanged manually each time I use a method of LinkedList, but it's bad de But once you've written it you can use it over and over again! – Will? Aug 9 at 14:12.
Ok now, I made a custom generic class that supports IEnumerable and is used as if it was a LinkedList, with the only difference that WPF gets notified of the changes. Please note that this solution only works for a reasonably small collection, I only have to manage around 30 elements max, so it's fine for me, but everytime you modify this collection, it is considered "Reset". Here goes the solution: /// /// This class is a LinkedList that can be used in a WPF MVVM scenario.
Composition was used instead of inheritance, /// because inheriting from LinkedList does not allow overriding its methods. /// /// public class ObservableLinkedList : INotifyCollectionChanged, IEnumerable { private LinkedList m_UnderLyingLinkedList; #region Variables accessors public int Count { get { return m_UnderLyingLinkedList. Count; } } public LinkedListNode First { get { return m_UnderLyingLinkedList.
First; } } public LinkedListNode Last { get { return m_UnderLyingLinkedList. Last; } } #endregion #region Constructors public ObservableLinkedList() { m_UnderLyingLinkedList = new LinkedList(); } public ObservableLinkedList(IEnumerable collection) { m_UnderLyingLinkedList = new LinkedList(collection); } #endregion #region LinkedList Composition public LinkedListNode AddAfter(LinkedListNode prevNode, T value) { LinkedListNode ret = m_UnderLyingLinkedList. AddAfter(prevNode, value); OnNotifyCollectionChanged(); return ret; } public void AddAfter(LinkedListNode node, LinkedListNode newNode) { m_UnderLyingLinkedList.
AddAfter(node, newNode); OnNotifyCollectionChanged(); } public LinkedListNode AddBefore(LinkedListNode node, T value) { LinkedListNode ret = m_UnderLyingLinkedList. AddBefore(node, value); OnNotifyCollectionChanged(); return ret; } public void AddBefore(LinkedListNode node, LinkedListNode newNode) { m_UnderLyingLinkedList. AddBefore(node, newNode); OnNotifyCollectionChanged(); } public LinkedListNode AddFirst(T value) { LinkedListNode ret = m_UnderLyingLinkedList.
AddFirst(value); OnNotifyCollectionChanged(); return ret; } public void AddFirst(LinkedListNode node) { m_UnderLyingLinkedList. AddFirst(node); OnNotifyCollectionChanged(); } public LinkedListNode AddLast(T value) { LinkedListNode ret = m_UnderLyingLinkedList. AddLast(value); OnNotifyCollectionChanged(); return ret; } public void AddLast(LinkedListNode node) { m_UnderLyingLinkedList.
AddLast(node); OnNotifyCollectionChanged(); } public void Clear() { m_UnderLyingLinkedList.Clear(); OnNotifyCollectionChanged(); } public bool Contains(T value) { return m_UnderLyingLinkedList. Contains(value); } public void CopyTo(T array, int index) { m_UnderLyingLinkedList. CopyTo(array, index); } public bool LinkedListEquals(object obj) { return m_UnderLyingLinkedList.
Equals(obj); } public LinkedListNode Find(T value) { return m_UnderLyingLinkedList. Find(value); } public LinkedListNode FindLast(T value) { return m_UnderLyingLinkedList. FindLast(value); } public Type GetLinkedListType() { return m_UnderLyingLinkedList.GetType(); } public bool Remove(T value) { bool ret = m_UnderLyingLinkedList.
Remove(value); OnNotifyCollectionChanged(); return ret; } public void Remove(LinkedListNode node) { m_UnderLyingLinkedList. Remove(node); OnNotifyCollectionChanged(); } public void RemoveFirst() { m_UnderLyingLinkedList.RemoveFirst(); OnNotifyCollectionChanged(); } public void RemoveLast() { m_UnderLyingLinkedList.RemoveLast(); OnNotifyCollectionChanged(); } #endregion #region INotifyCollectionChanged Members public event NotifyCollectionChangedEventHandler CollectionChanged; public void OnNotifyCollectionChanged() { if (CollectionChanged! = null) { CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.
Reset)); } } #endregion #region IEnumerable Members IEnumerator IEnumerable.GetEnumerator() { return (m_UnderLyingLinkedList as IEnumerable).GetEnumerator(); } #endregion }.
I think that eventually the simpler solution would be to calculate the start and end time beforehand and add them as properties on the ViewModel. Especially since you say that you may need this value in your business logic.
The start time and the end time depends on where the part is placed, it is highly variable. – Baboon Aug 9 at 13:24 When you move parts around, you can recalculate it. I mean...what do you think happens when you use converters and bindings, especially if you're going to use the reset event?
:) I'd say one method that iterates through your list and sets the start and end time is much simpler than adding a new collection class and using several converters. – Bubblewrap Aug 9 at 13:27.
It sounds to me like you have two different issues. One is managing a list of items for display, and the other is allowing an item to access its preceding and following items. That's how I'd approach it: add Previous and Next properties to the item class, set them when initially populating the collection, and then updating them when I insert and remove items from the list.
If you really want to go nuts and make a generic solution, you could implement an ILinkedListNode interface, and then subclass ObservableCollection where T : ILinkedListNode, overriding the various insert and remove methods to update the items' Previous and Next properties. That's what I'd do if I needed the solution to be reusable. But if not, I'd just make a view model class that wrapped the collection, exposing it as an Items property, and then implemented insert and remove commands that the UI can bind to.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.