From 1244ac0e77456e4cab03ffa634f04d3cbe48e483 Mon Sep 17 00:00:00 2001 From: Ferdinando Papale <4850119+papafe@users.noreply.github.com> Date: Tue, 7 May 2024 15:56:16 +0200 Subject: [PATCH] Simplified --- examples/QuickJournal/ViewModels/EntriesViewModel.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/QuickJournal/ViewModels/EntriesViewModel.cs b/examples/QuickJournal/ViewModels/EntriesViewModel.cs index 08d6e6fa4f..959fa41f4e 100644 --- a/examples/QuickJournal/ViewModels/EntriesViewModel.cs +++ b/examples/QuickJournal/ViewModels/EntriesViewModel.cs @@ -35,13 +35,13 @@ public async Task AddEntry() }); }); - await GoToEntry(entry); + await GoToEntry(new JournalEntryViewModel(entry)); } [RelayCommand] public async Task EditEntry(JournalEntryViewModel entry) { - await GoToEntry(entry.Entry); + await GoToEntry(entry); } [RelayCommand] @@ -53,17 +53,17 @@ await realm.WriteAsync(() => }); } - private async Task GoToEntry(JournalEntry entry) + private async Task GoToEntry(JournalEntryViewModel entry) { var navigationParameter = new Dictionary { - { "Entry", entry }, + { "Entry", entry.Entry }, }; await Shell.Current.GoToAsync($"entryDetail", navigationParameter); } } - public class WrapperCollection : INotifyCollectionChanged, IEnumerable + public class WrapperCollection : INotifyCollectionChanged, IReadOnlyList where T : IRealmObject where TViewModel : class { @@ -72,6 +72,8 @@ public class WrapperCollection : INotifyCollectionChanged, IEnume public int Count => _results.Count; + public TViewModel this[int index] => _viewModelFactory(_results[index]); + public event NotifyCollectionChangedEventHandler? CollectionChanged { add { _results.CollectionChanged += value; }