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:
<?xml version="1.0" encoding="utf-8" ?>
<!-- MY LISTVIEW. THE BINDING VALUES ARE CORRECT AND ARE PROPERTIES FROM LANCAMENTO CLASS -->
**
<ListView.ItemTemplate>
</ListView.ItemTemplate>
**
</StackLayout>
</Frame>
</StackLayout>
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 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 TO MY LISTVIEW
//THE LancamentosFatura.Lancamentos IS COMING WITH ITEMS, BUT THE LISTVIEW IS NOT BINDING THE ROWS
LancamentosCollection = new ObservableCollection(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; }
}