I have a ListView which I'm binding to a CollectionViewSource in code behind with:
collectionView = CollectionViewSource.GetDefaultView(TableView.ItemsSource);
collectionView.SortDescriptions.Clear();
collectionView.SortDescriptions.Add(new SortDescription(propertyName, direction));
The TableView is the ListView, the propertyName is the name of the column I want sorted, and direction is either ascending or descending.
The XAML has the following for ItemSource:
ItemsSource="{Binding Rows}"
The code behind has the following for the Rows:
List<TableRow> rows;
public List<TableRow> Rows
{
get { return rows; }
set
{
rows = value;
UpdateProperty("Rows");
}
}
the update is as follows:
public void Update()
{
...generate a list of rows...
Rows = ...rows...
}
The problem occurs when the Update is called, the list view does update, but loses the sorting set previously on the CollectionViewSource.