34 lines
937 B
C#
34 lines
937 B
C#
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.Windows.Input;
|
|
using NoteApp.Model;
|
|
using NoteApp.Service;
|
|
using NoteApp.View;
|
|
|
|
public class MainViewModel : INotifyPropertyChanged {
|
|
private readonly FileService _fileService;
|
|
private readonly INavigation _navigation;
|
|
|
|
public ObservableCollection<Note> Notes { get; set; } = [];
|
|
|
|
public ICommand LoadNoteCmd {get;}
|
|
|
|
public MainViewModel(FileService fileService, INavigation navigation){
|
|
_fileService = fileService;
|
|
_navigation = navigation;
|
|
|
|
LoadNotes().Wait();
|
|
|
|
LoadNoteCmd = new Command<Note>(async (note) => await LoadNote(note));
|
|
}
|
|
|
|
private async Task LoadNotes(){
|
|
Notes = await _fileService.LoadNotes();
|
|
}
|
|
|
|
private async Task LoadNote(Note note){
|
|
await _navigation.PushAsync(new NotePage(note));
|
|
}
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
} |