I have ObservableCollectionone that contains a custom object. Usually items are added at the end of the list.
What I'm looking for:
- Items are added from the top of the list.
- This can only be displayed in the user interface , my entire program already uses the data positions inside this list. Thus, the objects inside it may not change the order in the code.
This ObservableColectionstores Button objects (custom style). These buttons are displayed in ListBoxand inside StackPanelwith a horizontal layout (so that the buttons are conveniently arranged one after the other).
Problem:
Each created button receives DateTime. A newly added button always has a later date, and then a button before that. All calculations for this happen inside the timer (currently performed every second).
So, I basically sort at this time, but after 3 buttons all of a sudden, the button will be placed on the right side (instead of the left side).
For instance:
Btn3: 14:15:45 (right) Btn4: 14:16:00 (wrong) Btn2: 14:15:32 (right) Btn1: 14: 04: 17 (right)
The first three buttons are added correctly at the top of the list each time. And suddenly the fourth element is added to second place. Doesn't this always compare time? Each time a button is created, a method is called CollectionViewSource.
- CollectionViewSource ?