简体   繁体   English

显示 Xamarin forms 中的数据列表

[英]Displaying list of data in Xamarin forms

My application retrieves data from a firebase backend.我的应用程序从 firebase 后端检索数据。 The data is retrieved and put into a list object检索数据并放入列表 object

list type and its variables列表类型及其变量

      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>();

Getting the required data from firebase从 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();

When trying to display this list to a list view it will display as the object name eg当尝试将此列表显示到列表视图时,它将显示为 object 名称,例如

列表显示方式的屏幕截图

foundlogs 获取数据后持有的值

How do I display the data at each index of the list in a listview?如何在列表视图中显示列表的每个索引处的数据? For example if I wanted to display the UserID or logData as seen in the variable watch window, how would I do this?例如,如果我想显示变量 watch window 中看到的 UserID 或 logData,我该怎么做?

How I am currently displaying the list我目前如何显示列表

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

Thank you in advance先感谢您

you have to supply a template to tell the data how to be displayed - this is covered extensively in the docs您必须提供一个模板来告诉数据如何显示 - 这在文档中有广泛的介绍

<ListView>
  <ListView.ItemTemplate>
    <DataTemplate>
      <TextCell Text="{Binding UserID}" />
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM