Beispiel #1
0
        public HomePage()
        {
            //Here i am passin dbConnectivity
            _notesdb    = new NotesDB();
            _querytable = new QueryTable();



            //create button for Add Note
            var createButton = new Button {
                Text = "Add Note"
            };

            _lstview = new ListView {
            };
            //calling item cells
            _lstview.ItemTemplate = new DataTemplate(typeof(NoteItemCell));


            //CREATIN EVENT
            _lstview.ItemSelected += async(sender, e) =>
            {
                if (e.SelectedItem == null)
                {
                    return;
                }
                var detail_item = (NotesDB)e.SelectedItem;
                var detail_page = new EditPage();
                detail_page.BindingContext = detail_item;
                await Navigation.PushAsync(detail_page);

                ((ListView)sender).SelectedItem = null; //using for clear selected bg
            };
            //Add button event
            createButton.Clicked += (object sender, EventArgs e) =>
            {
                Navigation.PushAsync(new CreatePage());
            };
            //LAYOUT
            var mainLayout = new StackLayout {
            };

            mainLayout.Children.Add(createButton);
            mainLayout.Children.Add(_lstview);

            Content = mainLayout;
        }
        public CreatePage()
        {
            //Here pass DB connectivity

            _notesdb    = new NotesDB();
            _querytable = new QueryTable();


            //here i am creating Editor

            var noteEditor = new Editor
            {
                BackgroundColor   = Color.White,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            //Here i am creating Button

            var saveButton = new Button {
                Text = "Save", HorizontalOptions = LayoutOptions.FillAndExpand
            };
            var cancelButton = new Button {
                Text = "Cancel", HorizontalOptions = LayoutOptions.FillAndExpand
            };


            //Here i am creatin Event

            saveButton.Clicked += (object sender, EventArgs e) =>
            {
                _datetime = DateTime.Now;
                try
                {
                    InsertData(noteEditor.Text.ToString(), _datetime.ToString());

                    //I Creata Display alert
                    DisplayAlert("Alert", "Save Succesfully...!", "ok");
                    //Navigate
                    Navigation.PushAsync(new HomePage());
                }
                catch (Exception ex)
                {
                    string error = ex.ToString();
                    DisplayAlert("Opps...!", "Something went wrong.", "Ok");
                }
            };

            //Layout fOR BUTTON
            var btnStack = new StackLayout
            {
                Orientation       = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Children          =
                {
                    saveButton, cancelButton
                }
            };


            //Button Event for Cancel Button
            cancelButton.Clicked += (sender, e) =>
            {
                var NoteItem = (NotesDB)BindingContext;
                this.Navigation.PopAsync();
            };
            //Stack Layout fOR Editor
            Content = new StackLayout
            {
                VerticalOptions   = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Children          =
                {
                    noteEditor, btnStack
                }
            };
        }