Expand Wpf Treeview to support Sorting

前端 未结 3 1079
深忆病人
深忆病人 2021-01-21 09:48

Hi I created this small example, and I would like to expand it to support Sorting.

public class Country
{
    public string Name { get; set; }
    public int Sor         


        
3条回答
  •  隐瞒了意图╮
    2021-01-21 10:00

    I developed a View Model library which does a number of things, including letting you display hierarchical data in sorted order. The library is described in this article. The piece doesn't include a sorting example, but you can easily modify the Demo 2's View Model to sort its hierarchical data. Just do the following:

    1. The first of three boolean arguments passed to SampleTreeNodePM's base constructor indicates if the View Model collections should use the same indices as the Domain Model collections or not. Change this value to false.
    2. The last argument to the DesiredPosition method override's return value is a boolean that indicates whether to sort the View Model collection or not. Change this value to true.
    3. Following from the previous step, you now need to modify the Domain Model object, SampleTreeNode, to implement IComparable. The CompareTo method need simply delegate the job to the Name string property:

      public int CompareTo( SampleTreeNode other )
      {
          return Name.CompareTo( other.Name );
      }
      

    Regarding updating the position "on the fly" as your question says, just call my library's HierarchicalPresentationModel.UpdatePosition method after making the change.

提交回复
热议问题