Selecting data templates at runtime
You saw data templates in use with collection views in Chapter 5. Let’s revisit that code and expand upon it to allow us to modify the display of each object at runtime, based on the data in the object itself.
To recap, we started with PreferenceService
, where we mocked getting a list of Preference
objects. Now, we can get that from the API, with just a little work. Modify IPreferenceService
to remove GetPreferencesMock
.
Next, we need to significantly rework PreferenceService
to interact with the client. Delete what you have and use the following:
using ForgetMeNot.ApiClient; using ForgetMeNotDemo.Model; namespace ForgetMeNotDemo.Services; public class PreferenceService : IPreferenceService { readonly Client apiClient; public PreferenceService(Client apiClient) { this.apiClient = apiClient; } public async Task<List<Preference>> GetPreferences...