以Xamarin形式显示数据列表

时间:2020-07-07 23:51:22

标签: c# firebase xamarin xamarin.forms

我的应用程序从Firebase后端检索数据。检索数据并将其放入列表对象

列表类型及其变量

      public class UserLogs
{
    public Guid UserID { get; set; }
    public string logData { get; set; }
    public string sliderValue { get; set; }
    public string logTime { get; set; }

}

}

    List<UserLogs> foundLogs = new List<UserLogs>();

从firebase获取所需数据

    foundLogs = (await firebaseClient
        .Child("UserLogs")
        .OnceAsync<UserLogs>()).Where(a => a.Object.UserID == userID).Select(item => new UserLogs
        {
            UserID = item.Object.UserID,
            logData = item.Object.logData,
            sliderValue = item.Object.sliderValue,
            logTime = item.Object.logTime

           
        }).ToList();

尝试将此列表显示为列表视图时,它将显示为对象名称,例如

Screenshot of how list is displayed

values held by foundlogs after getting data

如何在列表视图的列表的每个索引处显示数据?例如,如果我想显示在变量监视窗口中看到的UserID或logData,我该怎么做?

我当前如何显示列表

    //list of logs being the name of the list view in the xaml file
    ListOfLogs.ItemsSource = foundLogs;

提前谢谢

1 个答案:

答案 0 :(得分:1)

您必须提供一个模板来告诉数据如何显示-docs

对此进行了广泛介绍。
<ListView>
  <ListView.ItemTemplate>
    <DataTemplate>
      <TextCell Text="{Binding UserID}" />
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>