private async void ListView_ItemTapped(object sender, ItemTappedEventArgs e) { (sender as ListView).SelectedItem = null; string de = await DisplayActionSheet("Выберите дейтсвие", "Отмена", null, "Добавить", "Изменить"); var id = (e.Item as Dish).Id; if (de == "Изменить") { var edPage = new EditOrCreateDishPage(id); edPage.Changed += EdPage_Changed; await Navigation.PushAsync(edPage); } else if (de == "Добавить") { string s = await DisplayActionSheet("Выберите приём пищи", "Отмена", null, "Завтрак", "Второй завтрак", "Обед", "Полдник", "Ужин", "Перекус"); if (s == "Отмена") { return; } var dd = new DayAndDish { Id = 0, Day = dayOfWeek, DishId = id, Type = mealToInt(s) }; App.Database.Database.Insert(dd); App.Database.DaysAndDishesList.Add(dd); Changed(this); } }
public DishPage(int id) { this.id = id; BackgroundColor = Color.White; dayAndDish = App.Database.DaysAndDishesList.Find(d => d.Id == id); var dish = App.Database.DishesList.Find(d => d.Id == dayAndDish.DishId); Title = dish.Name; ingridients = App.Database.IngredientsList.FindAll(i => i.DishId == dish.Id). Select(i => new IngredientView { Id = i.Id, CountAndUnit = i.Count.ToString() + " " + App.Database.NamesOfProudcts[i.ProductNameId].Unit, Name = App.Database.NamesOfProudcts[i.ProductNameId].Name }).ToList(); listView.ItemsSource = ingridients; listView.IsEnabled = false; listView.ItemTemplate = new DataTemplate(() => { Label nameLabel = new Label { HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, FontSize = Device.GetNamedSize(NamedSize.Default, typeof(Label)) * 1 }; nameLabel.SetBinding(Label.TextProperty, "Name"); Label countAndUnit = new Label { HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, FontSize = Device.GetNamedSize(NamedSize.Default, typeof(Label)) * 1 }; countAndUnit.SetBinding(Label.TextProperty, "CountAndUnit"); Grid cellGrid = new Grid { HorizontalOptions = LayoutOptions.FillAndExpand }; cellGrid.Children.Add(nameLabel, 0, 2, 0, 1); cellGrid.Children.Add(countAndUnit, 2, 3, 0, 1); return(new ViewCell { View = cellGrid }); }); Grid titleGrid = new Grid() { BackgroundColor = Color.White, ColumnSpacing = 2, RowSpacing = 2 }; titleGrid.Children.Add(new Label { BackgroundColor = Color.FromHex("c3fdff"), Text = " Игридиент", FontAttributes = FontAttributes.Bold, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, FontSize = Device.GetNamedSize(NamedSize.Default, typeof(Label)) * 1.1 }, 0, 2, 0, 1); titleGrid.Children.Add(new Label { HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, BackgroundColor = Color.FromHex("c3fdff"), FontAttributes = FontAttributes.Bold, Text = " Кол-во", FontSize = Device.GetNamedSize(NamedSize.Default, typeof(Label)) * 1.1 }, 2, 3, 0, 1); //ToolbarItem changeItem = new ToolbarItem //{ // Text = "ИЗМЕНИТЬ", // Order = ToolbarItemOrder.Primary, // Priority = 1 //}; //changeItem.Clicked += ChangeItem_Clicked; //ToolbarItems.Add(changeItem); ToolbarItem deleteItem = new ToolbarItem { Text = "УДАЛИТЬ", Order = ToolbarItemOrder.Primary, Priority = 0 }; deleteItem.Clicked += DeleteItem_Clicked; ToolbarItems.Add(deleteItem); ToolbarItem isCookedItem = new ToolbarItem { Text = "ПРИГОТОВЛЕНО", Order = ToolbarItemOrder.Primary, Priority = 0 }; isCookedItem.Clicked += IsCookedItem_Clicked; ToolbarItems.Add(isCookedItem); Content = new StackLayout { Padding = new Thickness(1, 2, 1, 1), BackgroundColor = Color.White, HorizontalOptions = LayoutOptions.FillAndExpand, Children = { //titleGrid, listView } }; }