public ThoughtEntryPage(RandomThoughtsPage parent, RandomThoughtDatabase database)
        {
            _parent = parent;
            _database = database;
            Title = "Enter a Thought";

            var entry = new Entry();
            var button = new Button
            {
                Text = "Add"
            };

            button.Clicked += async (object sender, EventArgs e) => {
                var thought = entry.Text;

                _database.AddThought(thought);

                await Navigation.PopAsync();


                _parent.Refresh();
            };

            Content = new StackLayout
            {
                Spacing = 20,
                Padding = new Thickness(20),
                Children = { entry, button },
            };
        }
        public RandomThoughtsPage(RandomThoughtDatabase database)
        {
            _database = database;
            Title = "Random Thoughts";
            var thoughts = _database.GetThoughts();

            _thoughtList = new ListView();
            _thoughtList.ItemsSource = thoughts;
            _thoughtList.ItemTemplate = new DataTemplate(typeof(TextCell));
            _thoughtList.ItemTemplate.SetBinding(TextCell.TextProperty, "Thought");
            _thoughtList.ItemTemplate.SetBinding(TextCell.DetailProperty, "CreatedOn");

            var toolbarItem = new ToolbarItem
            {
                Name = "Add",
                Command = new Command(() => Navigation.PushAsync(new ThoughtEntryPage(this, database)))
            };

            ToolbarItems.Add(toolbarItem);

            Content = _thoughtList;
        }
Beispiel #3
0
 public App()
 {
     // The root page of your application
     var database = new RandomThoughtDatabase();
     MainPage = new NavigationPage(new RandomThoughtsPage(database));
 }