示例#1
0
        public NoteEditPage(NoteEditModel model)
        {
            _model = model;
            _note  = model.Note;
            _isNew = model.IsNew;
            Title  = "Note";

            entry = new Entry()
            {
                Placeholder = "Title",
            };
            entry.Text = _note.Title;

            editor = new MyEditor()
            {
                Keyboard        = Keyboard.Create(KeyboardFlags.All),
                VerticalOptions = LayoutOptions.FillAndExpand,
                Text            = _note.Body
            };

            deleteCancel = new Button()
            {
                Text = _isNew ? "Cancel" : "Delete"
            };

            deleteCancel.Clicked += (object sender, EventArgs e) =>
            {
                _isCanceling = true;

                if (!_isNew)
                {
                    _note.IsDeleted = true;
                    _model.Save();
                }

                Navigation.PopAsync();
            };

            Content = new StackLayout()
            {
                Children =
                {
                    new Label {
                        Text = "Title"
                    },
                    entry,
                    new Label {
                        Text = "Note"
                    },
                    editor,
                    deleteCancel
                },
                Padding = new Thickness(5, 5, 5, 5)
            };
        }
示例#2
0
        protected NoteEditModel NewModel(Note note)
        {
            var model = new NoteEditModel()
            {
                Note  = note,
                IsNew = (note.Id <= 0),
            };

            model.Save = () =>
            {
                NoteAccessor.Save(model.Note);
                ReloadList();
            };

            model.Cancel = () =>
            {
                listView.ItemsSource = null;
                ReloadList();
            };

            return(model);
        }