Example #1
0
        //更新SortDescription类型
        static void UpdateSortDescription(ICollectionView view, SortData sortData)
        {
            var listCollec = view as ListCollectionView;
            var srcType    = view.SourceCollection.GetType();

            if (listCollec == null || (!srcType.IsGenericType && !srcType.IsArray))
            {
                view.SortDescriptions.Clear();
                view.SortDescriptions.Add(new SortDescription(sortData.PropertyName, sortData.Direction));
            }
            else
            {
                Type targetType;
                if (srcType.IsArray)
                {
                    targetType = srcType.GetElementType();
                }
                else
                {
                    targetType = srcType.GetGenericArguments()[0];
                }
                listCollec.CustomSort = new ListItemComparer(sortData, targetType);
            }

            sortData.Direction = GetReverseDirection(sortData.Direction);
        }
Example #2
0
 static void SetSortData(DependencyObject d, SortData value)
 {
     if (d == null)
     {
         return;
     }
     d.SetValue(SortDataProperty, value);
 }
Example #3
0
        static void OnSortPropertyChanged(DependencyObject dobj, DependencyPropertyChangedEventArgs e)
        {
            var column   = dobj as GridViewColumn;
            var propName = (string)e.NewValue;

            var sortData = GetSortData(column);

            if (sortData == null)
            {
                SetSortData(column, sortData = new SortData(propName));
            }

            if (column.CellTemplate == null
                &&
                column.CellTemplateSelector == null)
            {
                var binding = new Binding(sortData.PropertyName);
                column.DisplayMemberBinding = binding;
            }
        }
Example #4
0
 public ListItemComparer(SortData sortdata, Type targetType)
 {
     del       = CompileInstanceProperty(targetType, sortdata.PropertyName);
     Direction = sortdata.Direction;
 }