Listview loads items therefore without text

Asked

Viewed 36 times

-1

Listview loads items (including for possible editing), but without the item text:

[Função que realiza carregamento do ListView[1]

Classe Company

Teste: Carrega 3 linhas do ListView, inclusive para editar mas sem texto

1 answer

0

Good afternoon Felipe, follows an example of how to make a listview structure,

Model Class

  public class EmpresaCliente
  {
    public int IDEmpresa { get; set; }
    public int IDCadastroCliente { get; set; }
    public int IDCadastroEmpresa { get; set; }
    public int IDStatusEmail { get; set; }
    public string Nome { get; set; }
    public string Cnpj { get; set; }
    public string SituacaoEmpresa { get; set; }
    public string StatusEmail { get; set; }
    public string Email { get; set; }
  }

XAML

<ListView IsVisible="False" HeightRequest="-1" VerticalScrollBarVisibility="Never" ItemsSource="{Binding EmpresaCliente}" SeparatorColor="#010d47"  RowHeight="120" x:Name="lvEmpresa" ItemTapped="LvEmpresa_ItemTapped" SelectionMode="None">
                                    <ListView.ItemTemplate>
                                        <DataTemplate>
                                            <ViewCell>
                                                <StackLayout VerticalOptions="CenterAndExpand">
                                                    <StackLayout Orientation="Horizontal">



                                                        <Label Text="{Binding Nome}" TextColor="#010d47" FontAttributes="Bold"></Label>
                                                    </StackLayout>
                                                    <StackLayout Orientation="Horizontal" IsVisible="{Binding Cnpj, Converter={Helpers:NullValueBoolConverter}}">
                                                        <Label Text="CNPJ da Empresa:" FontAttributes="Bold"></Label>
                                                        <Label Text="{Binding Cnpj}"></Label>
                                                    </StackLayout>
                                                    <StackLayout Orientation="Horizontal">
                                                        <Label Text="Situação da Empresa:" FontAttributes="Bold"></Label>
                                                        <Label Text="{Binding SituacaoEmpresa}" TextColor="Red" IsVisible="{Binding SituacaoEmpresa, Converter={Helpers:NullValueBoolConverter}}">
                                                            <Label.Triggers>
                                                                <DataTrigger TargetType="Label" Binding="{Binding SituacaoEmpresa}" Value="ATIVA">
                                                                    <Setter Property="TextColor" Value="Green"/>
                                                                </DataTrigger>
                                                                <DataTrigger TargetType="Label" Binding="{Binding SituacaoEmpresa}" Value="INATIVA">
                                                                    <Setter Property="TextColor" Value="Red"/>
                                                                </DataTrigger>  
                                                            </Label.Triggers>
                                                        </Label>
                                                    </StackLayout>
                                                    <StackLayout Orientation="Horizontal"  IsVisible="{Binding StatusEmail, Converter={Helpers:NullValueBoolConverter}}">

                                                        <Label Text="Status:" FontAttributes="Bold"></Label>
                                                        <Label Text="{Binding StatusEmail}">
                                                            <Label.Triggers>
                                                                <DataTrigger TargetType="Label" Binding="{Binding StatusEmail}" Value="ENVIADO">
                                                                    <Setter Property="TextColor" Value="Green"/>
                                                                </DataTrigger>
                                                                <DataTrigger TargetType="Label" Binding="{Binding StatusEmail}" Value="AGUARDANDO ENVIO">
                                                                    <Setter Property="TextColor" Value="#facd34"/>
                                                                </DataTrigger>
                                                                <DataTrigger TargetType="Label" Binding="{Binding StatusEmail}" Value="AGUARDANDO RETORNO">
                                                                    <Setter Property="TextColor" Value="#facd34"/>
                                                                </DataTrigger>
                                                                <DataTrigger TargetType="Label" Binding="{Binding StatusEmail}" Value="SOLICITADO PPP POR E-MAIL">
                                                                    <Setter Property="TextColor" Value="#facd34"/>
                                                                </DataTrigger>
                                                                <DataTrigger TargetType="Label" Binding="{Binding StatusEmail}" Value="RECEBIDO">
                                                                    <Setter Property="TextColor" Value="Green"/>
                                                                </DataTrigger>
                                                                <DataTrigger TargetType="Label" Binding="{Binding StatusEmail}" Value="ENQUADRADO POR FUNÇÃO">
                                                                    <Setter Property="TextColor" Value="#facd34"/>
                                                                </DataTrigger>
                                                                <DataTrigger TargetType="Label" Binding="{Binding StatusEmail}" Value="AGUARDANDO LIGAÇÃO">
                                                                    <Setter Property="TextColor" Value="#facd34"/>
                                                                </DataTrigger>
                                                                <DataTrigger TargetType="Label" Binding="{Binding StatusEmail}" Value="SOLICITADO POR TELEFONE">
                                                                    <Setter Property="TextColor" Value="Green"/>
                                                                </DataTrigger>
                                                                <DataTrigger TargetType="Label" Binding="{Binding StatusEmail}" Value="AGUARDANDO PESQUISA">
                                                                    <Setter Property="TextColor" Value="DarkRed"/>
                                                                </DataTrigger>
                                                            </Label.Triggers>
                                                        </Label>
                                                    </StackLayout>
                                                </StackLayout>
                                            </ViewCell>
                                        </DataTemplate>
                                    </ListView.ItemTemplate>
                                </ListView>

C#

    public async void Populate()
    {

        try
        {
            var lista = await BuscarEmpresasAtreladas();
            if (lista.Count >= 1)
            {
                lvEmpresa.ItemsSource = lista;
                lvEmpresa.IsVisible = true;
            }
            else
            {
                lvEmpresa.IsVisible = false;
                lbEmpty.IsVisible = true;
            }
        }
        catch
        {
            await DisplayAlert("Ocorreu um erro", "Por favor verifique sua conexão com a internet", "OK");
        }
    }

If you design directly in C# you have to follow the same Binding model with the name of each Model element ex: {Binding Name}, {Bindind Cnpj} and so on.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.