Load data at Startup

Loading Albums on Startup

Our backend code provides a nice way to load the users collection from disk.
Add a method to MainWindowViewModel.cs like:
1
private async void LoadAlbums()
2
{
3
var albums = (await Album.LoadCachedAsync()).Select(x => new AlbumViewModel(x));
4
​
5
foreach (var album in albums)
6
{
7
Albums.Add(album);
8
}
9
​
10
foreach (var album in Albums.ToList())
11
{
12
await album.LoadCover();
13
}
14
}
Copied!
Register it in the constructor of the same class like:
1
RxApp.MainThreadScheduler.Schedule(LoadAlbums);
Copied!
As you can see it firstly uses the buisness logic apis to load the list of Albums. It then transforms each one into an AlbumViewModel. After this we add each AlbumViewModel instance to the ObservableCollection of Albums, this will instantly update the UI.
Note we then re-iterate over the Albums and asynchronously load each cover. Note that we do this after adding all the albums to the list, as its more important to quickly show the user all the albums available and then load the images.
image-20210310184202271
Last modified 19d ago
Export as PDF
Copy link