示例#1
0
 private void searchBar_Changed(object sender, EventArgs e)
 {
     if (TypeItem == TypeItemsOfColl.Constellation)
     {
         OurListView.ItemsSource = Constellations.Search(searchBar.Text);
     }
     else if (TypeItem == TypeItemsOfColl.Star)
     {
         OurListView.ItemsSource = Stars.Search(searchBar.Text);
     }
     else if (TypeItem == TypeItemsOfColl.Planet)
     {
         OurListView.ItemsSource = Planets.Search(searchBar.Text);
     }
 }
示例#2
0
        private void AddStar()
        {
            newStar = new Star("");
            Title   = "Добавление звезды";

            //данные о звезде
            nameEntry = new EntryCell {
                Label = "Название:", Placeholder = "Введите название", Keyboard = Keyboard.Default
            };
            weightEntry = new EntryCell {
                Label = "Масса:", Placeholder = "Введите массу в килограммах", Keyboard = Keyboard.Numeric,
            };
            radiusEntry = new EntryCell {
                Label = "Радиус:", Placeholder = "Введите радиус в метрах", Keyboard = Keyboard.Numeric
            };
            luminosityEntry = new EntryCell {
                Label = "Светимость:", Placeholder = "Введите светимость в лм", Keyboard = Keyboard.Numeric
            };
            root.Add(new TableSection("Общие данные")
            {
                nameEntry, weightEntry, radiusEntry, luminosityEntry
            });
            typePicker = new Picker {
                Title = "Тип звезды", ItemsSource = Enum.GetNames(typeof(Star.typeOfStar))
            };
            root.Add(new TableSection("Тип звезды")
            {
                new ViewCell {
                    View = typePicker
                }
            });

            //звездная система
            var searchConstellButton = new Button {
                Text = "Звездная система", TextColor = Color.Black, BackgroundColor = Color.FromHex("9E9E9E"), HorizontalOptions = LayoutOptions.Start
            };
            var searchConstellEntry = new Entry {
                Placeholder = "Звездная система", Keyboard = Keyboard.Default
            };

            searchParentListView = new ListView()
            {
                ItemsSource = Constellations,
            };
            searchConstellButton.Clicked += (s, e) =>
            {
                NavigationPage.SetHasBackButton(this, false);
                OurStackLayout.Children.Clear();
                searchConstellEntry.TextChanged += (_s, _e) =>
                {
                    searchParentListView.ItemsSource = Constellations.Search(searchConstellEntry.Text);
                };
                OurStackLayout.Children.Add(searchConstellEntry);
                OurStackLayout.Children.Add(searchParentListView);
                OurStackLayout.Children.Add(cancelButton);
            };
            searchParentListView.ItemTapped += (s, e) =>
            {
                searchConstellButton.Text = searchParentListView.SelectedItem.ToString();
                OurStackLayout.Children.Clear();
                OurStackLayout.Children.Add(tableview);
                OurStackLayout.Children.Add(SaveButton);
            };
            root.Add(new TableSection("Звездная система")
            {
                new ViewCell {
                    View = searchConstellButton
                }
            });

            //планеты
            var searchPlanetButton = new Button {
                Text = "Спутники", TextColor = Color.Black, BackgroundColor = Color.FromHex("9E9E9E"), HorizontalOptions = LayoutOptions.Start
            };
            var searchPlanetEntry = new Entry {
                Placeholder = "Планета", Keyboard = Keyboard.Default
            };
            var searchPlanetListView = new ListView {
                ItemsSource = Planets,
            };

            searchPlanetButton.Clicked += (s, e) =>
            {
                NavigationPage.SetHasBackButton(this, false);
                OurStackLayout.Children.Clear();
                searchPlanetEntry.TextChanged += (_s, _e) =>
                {
                    if (newStar.Planets != null)
                    {
                        searchPlanetListView.ItemsSource = (Planets.Search(searchPlanetEntry.Text)).Where(planets => planets.Star != newStar);
                    }
                    else
                    {
                        searchPlanetListView.ItemsSource = Planets.Search(searchPlanetEntry.Text);
                    }
                };
                OurStackLayout.Children.Add(searchPlanetEntry);
                OurStackLayout.Children.Add(searchPlanetListView);
                OurStackLayout.Children.Add(cancelButton);
            };
            searchPlanetListView.ItemTapped += async(s, e) =>
            {
                NavigationPage.SetHasBackButton(this, false);
                Planet planet = (Planet)searchPlanetListView.SelectedItem;
                if (await DisplayActionSheet(searchPlanetListView.SelectedItem.ToString(), "Отмена", null, "Добавить планету") == "Добавить планету")
                {
                    planet.Star                      = newStar;
                    searchPlanetEntry.Text           = "";
                    searchPlanetListView.ItemsSource = (Planets.Search(searchPlanetEntry.Text)).Where(planets => planets.Star != newStar);
                }
            };

            root.Add(new TableSection("Спутники")
            {
                new ViewCell {
                    View = searchPlanetButton
                }
            });
        }