有一个ListView控件,列头的名称和列数是不固定的。是动态的。!
如果单击列头排序的话,怎么实现?
请高手指点一二!

解决方案 »

  1.   

    click事件吧,我没做过,给你一些想法吧click事件里写排序
      

  2.   


            private void lvPackContent_Click(object sender, RoutedEventArgs e)
            {
                if (e.OriginalSource is GridViewColumnHeader)
                {
                    //Get clicked column
                    GridViewColumn clickedColumn = (e.OriginalSource as GridViewColumnHeader).Column;
                    if (clickedColumn != null)
                    {
                        //Get binding property of clicked column
                        string bindingProperty = (clickedColumn.DisplayMemberBinding as Binding).Path.Path;
                        SortDescriptionCollection sdc = lvPackContent.Items.SortDescriptions;
                        ListSortDirection sortDirection = ListSortDirection.Ascending;
                        if (sdc.Count > 0)
                        {
                            SortDescription sd = sdc[0];
                            sortDirection = (ListSortDirection)((((int)sd.Direction) + 1) % 2);
                            sdc.Clear();
                        }
                        sdc.Add(new SortDescription(bindingProperty, sortDirection));
                    }
                }
            }