Ejemplo n.º 1
0
        public void ExecuteSort(string propertyName, ListSortDirection direction)
        {
            var isAsc = direction == ListSortDirection.Ascending;

            var sortedQuery = propertyName switch
            {
                "Name" => isAsc
                    ? FileInfoList.OrderBy(file => file.Name, new FileNameComparer())
                    : FileInfoList.OrderByDescending(file => file.Name, new FileNameComparer()),
                "Size" => isAsc
                    ? FileInfoList.OrderBy(file => file.Size)
                    : FileInfoList.OrderByDescending(file => file.Size),
                "Type" => isAsc
                    ? FileInfoList.OrderBy(file => file.Type)
                    : FileInfoList.OrderByDescending(file => file.Type),
                "LastUpdateDate" => isAsc
                    ? FileInfoList.OrderBy(file => file.LastUpdateDate)
                    : FileInfoList.OrderByDescending(file => file.LastUpdateDate),
                _ => throw new ArgumentException(),
            };

            FileInfoList = new ObservableCollection <FileInfoViewModel>(sortedQuery);

            ////ソートアイコン表示をViewに依頼
            //Messenger.Instance.Send<SortMessage, MainWindow>(new SortMessage(propertyName, direction));

            //ソート情報保持
            switch (this.currentDirectory?.FileType)
            {
            case FileInfoViewModel.FileInfoType.Archive:
            case FileInfoViewModel.FileInfoType.ArchivedDirectory:
                this.archiveSortDescription = new SortDescription(propertyName, direction);
                break;

            case FileInfoViewModel.FileInfoType.Directory:
                this.directorySortDescription = new SortDescription(propertyName, direction);
                break;
            }
        }