示例#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 = "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;
        }
        public MainPageViewModel()
        {
            Notes = new ObservableCollection <NoteModel>();

            SaveNoteCommand = new Command(() =>
            {
                Notes.Add(new NoteModel
                {
                    Id        = Guid.NewGuid().ToString(),
                    Text      = NoteText,
                    Title     = Common.createTitle(NoteText),
                    Timestamp = DateTime.Now,
                    Time      = DateTime.Now.ToString("dd MMM yyyy")
                });
                NoteText = string.Empty;
            },
                                          () => !string.IsNullOrEmpty(NoteText));

            NoteSelectedCommand = new Command(async() =>
            {
                if (SelectedNote is null)
                {
                    return;
                }

                var detailViewModel = new DetailPageViewModel
                {
                    NoteText = SelectedNote.Text,
                    Notes    = Notes,
                    Id       = SelectedNote.Id
                };

                await Application.Current.MainPage.Navigation.PushAsync(new DetailPage(detailViewModel));

                SelectedNote = null;
            });
        }
示例#4
0
        public DetailPage(DetailPageViewModel viewModel)
        {
            BindingContext = viewModel;

            Title = "Notes Detail";

            BackgroundColor = Color.PowderBlue;

            var noteEditor = new Editor
            {
                Placeholder     = "Enter Note",
                BackgroundColor = Color.White,
                Margin          = new Thickness(2)
            };

            noteEditor.SetBinding(Editor.TextProperty, nameof(DetailPageViewModel.NoteText));

            var saveButton = new Button
            {
                Text            = "Save",
                VerticalOptions = LayoutOptions.Center,
                Margin          = new Thickness(2),
                BackgroundColor = Color.Green,
                TextColor       = Color.White
            };

            saveButton.SetBinding(Button.CommandProperty, nameof(DetailPageViewModel.SaveCommand));

            var deleteButton = new Button
            {
                Text            = "Delete",
                VerticalOptions = LayoutOptions.Center,
                Margin          = new Thickness(10),
                BackgroundColor = Color.Red,
                TextColor       = Color.White
            };

            deleteButton.SetBinding(Button.CommandProperty, nameof(DetailPageViewModel.DeleteCommand));

            var grid = new Grid
            {
                Margin = new Thickness(20, 40),

                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    }
                },
                RowDefinitions =
                {
                    new RowDefinition {
                        Height = new GridLength(4, GridUnitType.Star)
                    },
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Star)
                    },
                }
            };

            grid.Children.Add(noteEditor, 0, 0);
            Grid.SetColumnSpan(noteEditor, 2);

            grid.Children.Add(saveButton, 0, 1);
            grid.Children.Add(deleteButton, 1, 1);

            Content = grid;
        }