Exemplo n.º 1
0
        private static void OnListViewHeaderClick(object sender, RoutedEventArgs e)
        {
            SortableListView listView = e.Source as SortableListView;

            if (listView == null)
            {
                return;
            }

            GridViewColumnHeader header = e.OriginalSource as GridViewColumnHeader;

            if (header == null)
            {
                return;
            }
            var proName = header.Column.GetValue(SortFieldProperty) as string;

            if (proName == null)
            {
                return;
            }


            SortInfo sortInfo = listView.GetValue(SortInfoProperty.DependencyProperty) as SortInfo;

            if (sortInfo != null)
            {
                AdornerLayer.GetAdornerLayer(sortInfo.LastSortColumn).Remove(sortInfo.CurrentAdorner);
                listView.Items.SortDescriptions.Clear();
            }
            else
            {
                sortInfo = new SortInfo();
            }

            if (sortInfo.LastSortColumn == header)
            {
                (sortInfo.CurrentAdorner.Child as ListSortDecorator).SortDirection = (sortInfo.CurrentAdorner.Child as ListSortDecorator).SortDirection == ListSortDirection.Ascending ? ListSortDirection.Descending : ListSortDirection.Ascending;
            }
            else
            {
                sortInfo.CurrentAdorner = new UIElementAdorner(header, new ListSortDecorator());
            }

            sortInfo.LastSortColumn = header;
            listView.SetValue(SortInfoProperty, sortInfo);


            AdornerLayer.GetAdornerLayer(header).Add(sortInfo.CurrentAdorner);
            //SortDescription sortDescriptioin = new SortDescription()
            //{
            //    Direction = (sortInfo.CurrentAdorner.Child as ListSortDecorator).SortDirection,
            //    PropertyName = header.Column.GetValue(SortFieldProperty) as string ?? header.Column.Header as string
            //};
            if ((sortInfo.CurrentAdorner.Child as ListSortDecorator).SortDirection == ListSortDirection.Descending)
            {
                listView.OnSort(proName + " desc");
            }
            else
            {
                listView.OnSort(proName);
            }
            //listView.Items.SortDescriptions.Add(sortDescriptioin);
        }
Exemplo n.º 2
0
 internal static void SetSortInfo(DependencyObject obj, SortInfo value)
 {
     obj.SetValue(SortInfoProperty.DependencyProperty, value);
 }