Sorting folder names in Outlook VSTO
I'm using VSTO to build an Outlook add-in. I have a wpf TreeView with binding
<HierarchicalDataTemplate ItemsSource="{Binding Folders}">
开发者_运维技巧where Folders comes from a property that is set as
Folders = this.Application.ActiveExplorer().Session.Folders;
The folder hierarchy shows up correctly, but does not sort alphabetically like it does in Outlook. I don't see any methods to handle the sort natively. Just wondering if anyone else has done this and how they pulled it off.
I would sort the list myself. Assuming you want to sort by folder name, do this:
// Get the folders and sort them
SortedList<string, Folder> sortList = new SortedList<string, Folder>();
foreach (Folder nextFolder in this.Application.ActiveExplorer().Session.Folders)
sortList.Add(nextFolder.Name, nextFolder);
List<Folder> finalList = new List<Folder>();
finalList.AddRange(sortList.Values);
// Set the sorted list as the source
Folders = finalList;
精彩评论