0
I have a page with the expense list contains travel information like Description gross value, expenses and net total and even a list with my travel expenses. The problem is that when I will edit or create a new expense, and give the Popasync command to go back to Expense List, the updated expense list is loaded and also the updated trip values, but only Listview is updated and information passed by Bindcontext = trip is not updated. Does anyone have an idea how to update this information when returning to the previous page?
Viagem _viagem;
Movimento _movimento;
ObservableCollection<Despesa> _listaDespesa;
public ListaDespesaViagemPage (Viagem viagem, Movimento movimento)
{
InitializeComponent ();
_viagem = viagem;
_movimento = movimento;
}
private void carregarLista()
{
BindingContext = _viagem;
DespesaDal despesaDal = new DespesaDal();
_listaDespesa = new ObservableCollection<Despesa>(despesaDal.GetDespesasViagem(_viagem.ViagemId));
ltvDespesas.ItemsSource = _listaDespesa;
}
protected override void OnAppearing()
{
base.OnAppearing();
carregarLista();
}
[Resolution]
I used another approach that ended up solving.
Instead of BindingContext = _viagem
and in XAML have Text="{Binding Data}"
I named the label x:Name="lblData"
and at the event OnAppearing
i passed the information to the specific label lblData.Text = _viagem.Data.ToString("dd/MM/yyyy")
.
New Code became:
C#
private void carregarTela()
{
lblDescricao.Text = _viagem.Descricao;
lblData.Text = _viagem.Data.ToString("dd/MM/yyyy");
lblValorBruto.Text = String.Format("{0:C2}", _viagem.Valor);
lblDespesas.Text = String.Format("{0:C2}", _viagem.ValorDespesas);
lblLiquido.Text = String.Format("{0:C2}", _viagem.Liquido);
DespesaDal despesaDal = new DespesaDal();
_listaDespesa = new ObservableCollection<Despesa>(despesaDal.GetDespesasViagem(_viagem.ViagemId));
ltvDespesas.ItemsSource = _listaDespesa;
}
protected override void OnAppearing()
{
base.OnAppearing();
carregarTela();
}
XAML
<Label x:Name="lblDescricao"/>
<Label x:Name="lblData"/>
<Label x:Name="lblValorBruto" />
<Label x:Name="lblDespesas"/>
<Label x:Name="lblLiquido"/>
Thank you all...
Thank you for the answer. I will test this solution on another screen with the same problem, because in this solved using another approach...
– João Paulo