I’m binging DataGrid to ObservableCollection I update collection on timer and grid updates nicely which is what I want.
However, even though I can sort collection on initial population – when I append new items they go to bottom. User can sort grid and then it looks good.
I would like to “force” grid to sort by specific column when it is initialized. Can it be done in XAML or somehow in MVVM manner?
EDIT
Just to give more details. This is mail client main screen. I’ve got service that polls for data and if new mail arrived – it get’s appended to collection. Sorting at this point is not desirable for couple reasons. First, this is list of object. Second, user may decided to sort by other column using DataGrid
It feels right to set grid to sort by column I initially want (Time Received) and let users sort by any column while preserving this order when new items arrive.
[Edit] Edited the answer to correspond to the solution
You can try adding SortDescriptions by including the Collection in a collectionView. In example.
Then in your ItemsSource set the following binding.