C# 如何从对象获取数据?

C# 如何从对象获取数据?,c#,listview,object,xamarin,xamarin.forms,C#,Listview,Object,Xamarin,Xamarin.forms,我有一个带有值的列表视图。当我选择一个项目时,我会将一个包含所有值的对象传递到另一个页面,我想显示所有值,但不显示。 对象“envolvselect”有4个值(NomePesquisa、NomeMae、NomePai和DtNasc),我想展示它们。。。调试时,值传递正确。问题是向他们展示 [第1页] using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.

我有一个带有值的列表视图。当我选择一个项目时,我会将一个包含所有值的对象传递到另一个页面,我想显示所有值,但不显示。 对象“envolvselect”有4个值(NomePesquisa、NomeMae、NomePai和DtNasc),我想展示它们。。。调试时,值传递正确。问题是向他们展示

[第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));
                    });

                }
            });


        }
    }
}
[第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;
        }

    }
}
在第3页,我绑定了标签,因此in.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>

我在您的第3页Xaml或代码中没有看到
绑定上下文

您可以将其指定为:

public EnvolvidoDetalhe(object envolvSelec)
{
    InitializeComponent();
    this.envolvSelec = envolvSelec;
    BindingContext = envolvSelec;
}

现在,您的绑定标签通过对象的公共属性(NomePesquisa、NomeMae等)知道从哪个对象获取数据。

My hero!!!!谢谢我的朋友。。。我再问你一件事。。。当我执行{Binding}时,如何在之前显示字符串?像这样:“Name:”(绑定结果)现在,我正在显示(绑定结果)我发现了“{BINDING NomePesquisa,StringFormat='Nome:{0}}}”,也非常感谢!!!
public EnvolvidoDetalhe(object envolvSelec)
{
    InitializeComponent();
    this.envolvSelec = envolvSelec;
    BindingContext = envolvSelec;
}