i have a Listview with values. When i select a item, i pass a object with all values to another page and i want to show all the values, but is not appearing. Object "envolvselect" has 4 values (NomePesquisa, NomeMae, NomePai and DtNasc) and i want to show them... when i debug, the values are passing correct. The problem is to show them!
我有一个带有值的Listview。当我选择一个项目时,我将一个包含所有值的对象传递给另一个页面,我想显示所有值,但是没有出现。对象“envolvselect”有4个值(NomePesquisa,NomeMae,NomePai和DtNasc),我想要显示它们...当我调试时,值传递正确。问题是要向他们展示!
[Page 1]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AppMobile.Services;
using AppMobile.Models;
using Xamarin.Forms;
using System.Diagnostics;
namespace AppMobile.Views
{
public partial class BuscaEnvolvidos : ContentPage
{
public BuscaEnvolvidos()
{
InitializeComponent();
}
public void ConsultarClick (object sender, EventArgs e)
{
var ListaDados = new ListView();
string nomepesquisa = entryNmPesq.Text;
string nomemae = entryNmMae.Text;
string nomepai = entryNmPai.Text;
string dtnasc = entrydtNasc.Text;
ApiCall apiCall = new ApiCall();
apiCall.GetResponse<List<Envolvidos>>("nomes", "Envolvidos", nomepesquisa, nomemae, nomepai, dtnasc).ContinueWith(t =>
{
//Caso tenha erro na requisição
if (t.IsFaulted || t.IsCanceled)
{
Debug.WriteLine(t.Exception.Message);
Device.BeginInvokeOnMainThread(() =>
{
DisplayAlert("Erro", "Ocorreu um erro na Requisição. Tente novamente", "Ok");
});
}
//Caso a requisição ocorra sem problemas, cairemos aqui
else
{
//Se Chegarmos aqui, está tudo ok, agora itemos tratar nossa Lista
//Aqui Usaremos a Thread Principal, ou seja, a que possui as references da UI
Device.BeginInvokeOnMainThread(() =>
{
ListaDados.ItemsSource = t.Result;
Navigation.PushAsync(new ResultadosBuscados(ListaDados.ItemsSource));
});
}
});
}
}
}
[Page 2]
namespace AppMobile.Views
{
public partial class ResultadosBuscados : ContentPage
{
public ResultadosBuscados(IEnumerable dadosPesquisados)
{
InitializeComponent();
ListaBuscados.ItemsSource = dadosPesquisados;
}
public void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var envolvSelec = e.SelectedItem;
if (envolvSelec == null)
return;
this.Navigation.PushAsync(new EnvolvidoDetalhe(envolvSelec));
this.ListaBuscados.SelectedItem = null;
}
}
}
[Page 3]
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using Xamarin.Forms;
namespace AppMobile.Views
{
public partial class EnvolvidoDetalhe : ContentPage
{
private object envolvSelec;
public EnvolvidoDetalhe(object envolvSelec)
{
InitializeComponent();
this.envolvSelec = envolvSelec;
}
}
}
On the Page 3 i binded the labels, so in .xaml is:
在标签上绑定了标签,因此.xaml是:
<ListView x:Name="ListaInfos" SeparatorColor="#F4B400" SeparatorVisibility="Default" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout Spacing="1">
<Label x:Name="lblNome" Text="{Binding NomePesquisa}" TextColor="#555" FontSize="18" FontAttributes="Bold"></Label>
<Label x:Name="lblNomeMae" Text="{Binding NomeMae}" TextColor="#555" FontSize="12"></Label>
<Label x:Name="lblNomePai" Text="{Binding NomePai}" TextColor="#555" FontSize="12"></Label>
<Label x:Name="lblDataNasc" Text="{Binding DtNasc}" TextColor="#555" FontSize="12" ></Label>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
1 个解决方案
#1
0
I do not see the BindingContext
in your page 3 Xaml or code.
我没有在你的第3页Xaml或代码中看到BindingContext。
You can assign it as such:
您可以这样分配:
public EnvolvidoDetalhe(object envolvSelec)
{
InitializeComponent();
this.envolvSelec = envolvSelec;
BindingContext = envolvSelec;
}
Now your bound labels in know which object to obtain their data from via that object's public properties (NomePesquisa, NomeMae, etc....).
现在你的绑定标签知道哪个对象通过该对象的公共属性(NomePesquisa,NomeMae等等)获取数据。
#1
0
I do not see the BindingContext
in your page 3 Xaml or code.
我没有在你的第3页Xaml或代码中看到BindingContext。
You can assign it as such:
您可以这样分配:
public EnvolvidoDetalhe(object envolvSelec)
{
InitializeComponent();
this.envolvSelec = envolvSelec;
BindingContext = envolvSelec;
}
Now your bound labels in know which object to obtain their data from via that object's public properties (NomePesquisa, NomeMae, etc....).
现在你的绑定标签知道哪个对象通过该对象的公共属性(NomePesquisa,NomeMae等等)获取数据。