Add Data Persistence
Persistence is the job of the business logic (
model) code. However here we will see it's very simple to wire this up to the UI.
Add the following method to
AlbumViewModelthis will call our backend logic to save the Album to the users collection. The backend also provides a way to cache the album bitmap. It provides us a stream we can save our bitmap to.
public async Task SaveToDiskAsync()
if (Cover != null)
var bitmap = Cover;
await Task.Run(() =>
using (var fs = _album.SaveCoverBitmapStream())
Now we can simply call this method when our dialog returns its result in
BuyMusicCommand = ReactiveCommand.CreateFromTask(async () =>
var store = new MusicStoreViewModel();
var result = await ShowDialog.Handle(store);
if (result != null)