Reverse ObservableCollection

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 ?

+2
4

XAML? , , . , DocProps, .

        <ListBox.DataContext>
            <CollectionViewSource Source="{Binding Path=DocProps}">
                <CollectionViewSource.SortDescriptions>
                    <scm:SortDescription PropertyName="Date" Direction="Desc" />
                </CollectionViewSource.SortDescriptions>
            </CollectionViewSource>
        </ListBox.DataContext>

, . , 001 - 00n .

, . .

     Text="{Binding Path=Date, Mode=OneWay, StringFormat={}{0:s}}"
+4

, Ticks DateTime , , cource - .

0

ICollectionView , , .

, . btw icollectionview , .

0

Siva, , , http://connect.microsoft.com/VisualStudio/feedback/details/592897/collectionviewsource-sorting-only-the-first-time-it-is-bound-to-a-source - . DataGrid, , :

Greg Bachraty 28.02.2011 6:50

DataGrid:

public class SDataGrid : DataGrid
{
    static SDataGrid()
    {
        ItemsControl.ItemsSourceProperty.OverrideMetadata(typeof(SDataGrid), new FrameworkPropertyMetadata((PropertyChangedCallback)null, (CoerceValueCallback)null));
    }
}

The only thing calling the coerce callback in the current implementation is to clear the sort descriptions. You can simply “cut” this code override metadata. Invalid in Silverlight: The OverrideMetadata API is not public. Although I'm not sure that Silverlight depends on this error. Other risks and side effects may apply.

0
source

All Articles