private static void SetGlyphForInitialSort(ListView listView) { if (!GetAutoSort(listView) || !GetShowSortGlyph(listView)) return; var view = CollectionViewSource.GetDefaultView(listView.Items); if (!view.SortDescriptions.Any()) return; var headerRow = listView.FindDescendants<GridViewHeaderRowPresenter>().FirstOrDefault(); if (headerRow == null) return; var sort = view.SortDescriptions.First(); var headers = headerRow.FindDescendants<GridViewColumnHeader>(); foreach (var header in headers) { if (header.Column == null) continue; string sortPropertyName = GetSortPropertyName(header.Column); if (sortPropertyName != sort.PropertyName) continue; AddSortGlyph( header, sort.Direction, sort.Direction == ListSortDirection.Ascending ? GetSortGlyphAscending(listView) : GetSortGlyphDescending(listView)); SetSortedColumnHeader(listView, header); break; } }