1
I am trying to make a List string in Xamarin , this list auto increments according to an attribute being declared true;
public bool TemPão { get; set; }
public bool TemBife { get; set; }
public bool TemPresunto { get; set; }
public bool TemMussarela { get; set; }
public bool TemOvo { get; set; }
public bool TemBacon { get; set; }
public bool TemCheddar { get; set; }
public bool TemCalabresa { get; set; }
public bool TemCatupiri { get; set; }
public bool TemSalada { get; set; }
public string IngredientesPrato
{
get
{
List<string> Ingredientes = new List<string>();
if (TemPão) { Ingredientes.Add("Pão"); }
if (TemBife) { Ingredientes.Add("Bife"); }
if (TemPresunto) { Ingredientes.Add("Presunto"); }
if (TemMussarela){ Ingredientes.Add("Mussarela"); }
if (TemOvo) { Ingredientes.Add("Ovo"); }
if (TemBacon) { Ingredientes.Add("Bacon"); }
if (TemCheddar) { Ingredientes.Add("Cheddar"); }
if (TemCalabresa){ Ingredientes.Add("Calabresa"); }
if (TemCatupiri) { Ingredientes.Add("Catupiri"); }
if (TemSalada) { Ingredientes.Add("Alface, Tomate"); }
//return string.Join(", ", Ingredientes);
string ingredientes="";
foreach(string ingrediente in Ingredientes)
{
ingredientes += ingrediente + ", ";
ingredientes = ingrediente.TrimEnd(',') + ".";
}
return ingredientes;
}
only that I could not test yet, because I can not declare the Ingredienteprato in my listing
namespace AppGourmet.Models
public class ListagemPratos
{
public List<Pratos> Pratos { get; private set; }
public List<Ingredientes> Ingredientes { get; set; }
public ListagemPratos()
{
this.Pratos = new List<Pratos>()
{
new Pratos { Nome = "X-Burger", Preco = 10, ImageLanche="Burger.png",
TemPão = true, TemBife = true, TemPresunto = true, TemSalada = true,TemBacon=false,
TemCalabresa=false,TemOvo=true,TemCheddar=false,TemCatupiri=false,TemMussarela=false,
//declaração do IngredientePrato},
};
}
}
and finally, "bindar" in the shampoo displaying the list horizontally
<ListView x:Name="ListViewPratos"
BackgroundColor="White"
ItemsSource="{Binding Pratos}"
SelectedItem="{Binding PratoSelecionado}"
HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout Orientation="Vertical" BackgroundColor="White" Margin="10">
<StackLayout Orientation="Horizontal" BackgroundColor="White">
<Image Source="{Binding ImageLanche}" HeightRequest="65" WidthRequest="65"></Image>
<Label Text="{Binding Nome}" FontSize="20" VerticalOptions="Center" TextColor="Blue"></Label>
<Label Text=" " HorizontalOptions="StartAndExpand" VerticalOptions="Center"></Label>
<Label Text="{Binding PrecoFormatado}" FontAttributes="Bold" VerticalOptions="Center" TextColor="Black"></Label>
</StackLayout>
//bindar a List<string> horizontalmente
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I would like to help, but I do not understand what your question is specifically. In addition, there are some problems of modeling the solution, but if it is didactic it is not the case. With what even you are having difficulty?
– Diego Rafael Souza