public MainPageViewModel() { Notes = new ObservableCollection <NoteModel>(); SaveNoteCommand = new Command(() => { Notes.Add(new NoteModel { Text = NoteText }); NoteText = string.Empty; }, () => !string.IsNullOrEmpty(NoteText)); EraseNotesCommand = new Command(() => Notes.Clear()); NoteSelectedCommand = new Command(async() => { if (SelectedNote is null) { return; } var detailViewModel = new DetailPageViewModel { NoteText = SelectedNote.Text }; await Application.Current.MainPage.Navigation.PushAsync(new DetailPage(detailViewModel)); SelectedNote = null; }); }
public DetailPage(DetailPageViewModel viewModel) { BindingContext = viewModel; Title = "Notes Detail"; BackgroundColor = Color.PowderBlue; var textLabel = new Label { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.CenterAndExpand }; textLabel.SetBinding(Label.TextProperty, nameof(DetailPageViewModel.NoteText)); var exitButton = new Button { Text = "Pop", VerticalOptions = LayoutOptions.Center, Margin = new Thickness(20), BackgroundColor = Color.Red, TextColor = Color.White, FontSize = 20 }; exitButton.SetBinding(Button.CommandProperty, nameof(DetailPageViewModel.ExitCommand)); var stackLayout = new StackLayout { Margin = new Thickness(20, 40) }; stackLayout.Children.Add(textLabel); stackLayout.Children.Add(exitButton); Content = stackLayout; }