【问题标题】:Sorting folder names in Outlook VSTO在 Outlook VSTO 中对文件夹名称进行排序
【发布时间】:2011-07-13 06:19:41
【问题描述】:

我正在使用 VSTO 构建 Outlook 加载项。我有一个带绑定的 wpf TreeView

<HierarchicalDataTemplate ItemsSource="{Binding Folders}">

其中文件夹来自设置为的属性

Folders = this.Application.ActiveExplorer().Session.Folders;

文件夹层次结构正确显示,但不像在 Outlook 中那样按字母顺序排序。我没有看到任何本地处理排序的方法。只是想知道是否有其他人这样做过,以及他们是如何做到的。

【问题讨论】:

    标签: c# wpf outlook vsto


    【解决方案1】:

    我会自己对列表进行排序。假设您要按文件夹名称排序,请执行以下操作:

    // 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;
    

    【讨论】:

    • 这样做会破坏层次结构,对吗?我需要维护完整的文件夹/子文件夹层次结构,只需排序。
    • 为什么会破坏层次结构?文件夹仍然具有相同的子级。它只是更改集合中 Folder 对象的顺序,不会更改 Folder 的任何成员。如果您需要对所有子节点进行排序,请告诉我,我将编辑我的答案(需要使用不同的方法)。
    猜你喜欢
    • 2021-08-20
    • 2020-04-19
    • 1970-01-01
    • 1970-01-01
    • 2011-07-12
    • 2017-01-28
    • 2015-09-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多