Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

ListView not binding in Prism 7

$
0
0

Below I am showing my xaml file with a ListView control and my ViewModel... I am trying to binding some items to the ListView, but nothing happens.

I am using Prism 7 as my MVVM framework.

This is my xaml with a listview:

            <ListView x:Name="lancamentos" ItemsSource="{Binding LancamentosCollection}">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout Orientation="Horizontal">
                                <Label Text="{Binding Descricao}" HorizontalOptions="StartAndExpand" VerticalOptions="Center"></Label>
                                <Label Text="{Binding Data}" HorizontalOptions="StartAndExpand" VerticalOptions="Center"></Label>
                                <Label Text="{Binding Valor}" HorizontalOptions="StartAndExpand" VerticalOptions="Center"></Label>
                                <Label Text="{Binding Tipo}" HorizontalOptions="StartAndExpand" VerticalOptions="Center"></Label>
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

This is my ViewModel:

public class ClosedIncomePageViewModel : ViewModelBase
{
    private LancamentosFatura _lancamentosFatura;
    private Fatura _fatura;

//HERE IS MY COLLECTION USED AS A SOURCE IN MY LISTVIEW. IT IS PUBLIC, CAUSE IT IS AN ESSENCIAL CONFIGURATION !!!
    public ObservableCollection<Lancamento> LancamentosCollection { get; set; }

    public Fatura Fatura
    {
        get { return _fatura; }
        set { SetProperty(ref _fatura, value); }
    }

    public LancamentosFatura LancamentosFatura
    {
        get { return _lancamentosFatura; }
        set { SetProperty(ref _lancamentosFatura, value); }
    }

    public ClosedIncomePageViewModel(INavigationService navigationService)
        : base(navigationService)
    {
        LancamentosFatura = new LancamentosFatura();
    }

    public override void OnNavigatedTo(NavigationParameters parameters)
    {
        if (parameters.ContainsKey("lancamentos_fatura"))
        {
            LancamentosFatura = (LancamentosFatura)parameters["lancamentos_fatura"];

            //Atribui apenas o segundo elemento da lista de faturas (equivalente a primeira fatura fechada)
            LancamentosFatura.FaturaVisualizada = LancamentosFatura.Faturas[1];

            //Obtem os lançamentos e carrega Listview
            ObterLancamentos();
        }
    }

    private async void ObterLancamentos()
    {
        try
        {
            //Carrega o Loading...
            using (UserDialogs.Instance.Loading("Carregando..."))
            {
                await Task.Run(() => ProcessarXML());
            }

            if (LancamentosFatura.Lancamentos != null)
            {
                if (LancamentosFatura.Status.Codigo == "0")
                {

        //HERE I AM BINDING THE LIST<LANCAMENTO> TO MY LISTVIEW
        //THE LancamentosFatura.Lancamentos IS COMING WITH ITEMS, BUT THE LISTVIEW IS NOT BINDING THE ROWS
                    LancamentosCollection = new ObservableCollection<Lancamento>(LancamentosFatura.Lancamentos);

                    Toast("Lançamentos da fatura fechada recuperadas com sucesso", System.Drawing.Color.Green);
                }
                else
                {
                    Toast("Não foi possível recuperar os lançamentos da fatura fechada", System.Drawing.Color.Red);
                }
            }
            else
            {
                Toast("Não foram encontrados lançamentos para a fatura fechada", System.Drawing.Color.Orange);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    private void ProcessarXML()
    {
    ...
    }
}

Here is my Lancamento class:

public class Lancamento : ModelBase
{
    public Lancamento(XmlElement element)
    {
        Data = GetTextValue(element, "dt_lancto");
        Descricao = GetTextValue(element, "desc_lancto");
        Valor = GetTextValue(element, "vl_lancto");
        Tipo = (GetTextValue(element, "tp_sinal") == "C" ? "Crédito" : "Débito");
    }

    public string Data { get; set; }
    public string Descricao { get; set; }
    public string Valor { get; set; }
    public string Tipo { get; set; }
}

Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>