two fixes
This commit is contained in:
parent
60ec37b2c7
commit
e7a54b99ea
@ -7,14 +7,14 @@ namespace MauiApp2.ViewModels
|
||||
{
|
||||
internal class NotesViewModel : IQueryAttributable
|
||||
{
|
||||
public ObservableCollection<ViewModels.NoteViewModel> AllNotes { get; }
|
||||
public ObservableCollection<NoteViewModel> AllNotes { get; }
|
||||
public ICommand NewCommand { get; }
|
||||
public ICommand SelectNoteCommand { get; }
|
||||
public NotesViewModel()
|
||||
{
|
||||
AllNotes = new ObservableCollection<ViewModels.NoteViewModel>(Models.Note.LoadAll().Select(n => new NoteViewModel(n)));
|
||||
AllNotes = new ObservableCollection<NoteViewModel>(Note.LoadAll().Select(n => new NoteViewModel(n)));
|
||||
NewCommand = new AsyncRelayCommand(NewNoteAsync);
|
||||
SelectNoteCommand = new AsyncRelayCommand<ViewModels.NoteViewModel>(SelectNoteAsync);
|
||||
SelectNoteCommand = new AsyncRelayCommand<NoteViewModel>(SelectNoteAsync);
|
||||
}
|
||||
|
||||
private async Task NewNoteAsync()
|
||||
@ -45,11 +45,14 @@ namespace MauiApp2.ViewModels
|
||||
|
||||
// If note is found, update it
|
||||
if (matchedNote != null)
|
||||
{
|
||||
matchedNote.Reload();
|
||||
AllNotes.Move(AllNotes.IndexOf(matchedNote), 0);
|
||||
}
|
||||
|
||||
// If note isn't found, it's new; add it.
|
||||
else
|
||||
AllNotes.Add(new NoteViewModel(Note.Load(noteId)));
|
||||
AllNotes.Insert(0, new NoteViewModel(Models.Note.Load(noteId)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="MauiApp2.Views.AllNotesPage"
|
||||
xmlns:viewModels="clr-namespace:MauiApp2.ViewModels"
|
||||
NavigatedTo="ContentPage_NavigatedTo"
|
||||
Title="Your Notes">
|
||||
<ContentPage.BindingContext>
|
||||
<viewModels:NotesViewModel />
|
||||
|
||||
@ -6,4 +6,8 @@ public partial class AllNotesPage : ContentPage
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
private void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e)
|
||||
{
|
||||
notesCollection.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user