C# IReadOnlyList Items laden
Wie kann man manuell Items in eine IReadOnlyList laden
Lösung
Man kann die Elemente einer IReadOnlyListe in eine
ObservableList mit .Add(Element) laden
Die ObservableList oder IEnumerable List kann man mit
OrderBy sortieren.
//< get Files sorted >
ObservableCollection<StorageFile>
fileList = new ObservableCollection<StorageFile>();
IReadOnlyList<StorageFile>
files = null;
files = await folder.GetFilesAsync();
foreach (StorageFile file in files)
{
fileList.Add(file);
}
fileList.OrderByDescending((x)
=> x.DisplayName);
|
Code
Beispiel C#
IReadOnly
List, ObservableCollection, sortieren
public async void fpReadFiles_CameraFolder(StorageFolder
folder)
{
//------------<
fxReadFiles_inFolder()------------
ctlFiles.Items.Clear();
//< check >
if (folder == null) return;
//</ check >
//< get Files sorted >
ObservableCollection<StorageFile> fileList = new
ObservableCollection<StorageFile>();
if (IsAndroid == true)
{
IReadOnlyList<StorageFile>
files = null;
files = await folder.GetFilesAsync();
foreach (StorageFile file in files)
{
fileList.Add(file);
}
}
else
{
foreach (StorageFolder appleFolder in await folder.GetFoldersAsync())
{
if (appleFolder.Name.Contains("APPLE"))
{
IReadOnlyList<StorageFile> files = null;
files = await appleFolder.GetFilesAsync();
foreach (StorageFile file in files)
{
fileList.Add(file);
}
}
}
}
//*order List
fileList.OrderByDescending((x)
=> x.DisplayName);
//IEnumerable<StorageFile>
sortedFiles = files.OrderByDescending((x) => x.DisplayName);
//</ get Files sorted >
fpLoadItems_in_Drive(fileList);
//------------</
fxReadFiles_inFolder()------------
}
|
Überleitung
Sortieren einer Readable Liste
IReadOnlyList<StorageFile> files =
await folder.GetFilesAsync();
IEnumerable<StorageFile> sortedFiles =
files.OrderByDescending((x) => x.DisplayName);
|