IOrderedEnumerable <TreeViewItem <TreeElementType> > GetInitialOrder(IEnumerable <TreeViewItem <TreeElementType> > types, int[] history) { int index = history[0]; TreeViewColumn column = this.columns[index]; bool ascending = multiColumnHeader.IsSortedAscending(index); // If a sorting function was provided if (column.selectorFunction != null) { return(types.Order(l => column.selectorFunction(l), ascending)); } // Default return(types.Order(l => l.item.name, ascending)); }
private void SortByMultipleColumns() { int[] sortedColumns = multiColumnHeader.state.sortedColumns; if (sortedColumns.Empty()) { return; } var types = rootItem.children.Cast <TreeViewItem <TreeElementType> >(); var orderedQuery = GetInitialOrder(types, sortedColumns); for (int c = 1; c < sortedColumns.Length; ++c) { int index = sortedColumns[c]; TreeViewColumn column = this.columns[index]; bool ascending = this.multiColumnHeader.IsSortedAscending(index); orderedQuery = orderedQuery.ThenBy(l => column.selectorFunction(l), ascending); } this.rootItem.children = orderedQuery.Cast <TreeViewItem>().ToList(); }