Пример #1
0
        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;
            });
        }
Пример #2
0
        public DetailPage(DetailPageViewModel viewModel)
        {
            BindingContext = viewModel;

            Title = "Note 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            = "back",
                BackgroundColor = Color.SteelBlue,
                TextColor       = Color.White,
                FontSize        = 20
            };

            exitButton.SetBinding(Button.CommandProperty, nameof(DetailPageViewModel.ExitCommand));

            var stack = new StackLayout
            {
                Margin = new Thickness(20, 40)
            };

            stack.Children.Add(textLabel);
            stack.Children.Add(exitButton);

            Content = stack;
        }