c# - 我的 ListView 没有正确显示结果
问题描述
我的 ListView 麻烦的第二版 :( 这是我的代码:
public class Person
{
public string ID { get; set; }
public string NAME { get; set; }
public string CODE { get; set; }
public string CITY { get; set; }
}
public List<Person> CL = new List<Person>() {
new Person() { ID = "kkkkkkk", NAME = "dsdsdsd", CODE = "sdsdsd", CITY = "sdsdsdsd" },
new Person() { ID = "kkkkkkk", NAME = "dsdsdsd", CODE = "sdsdsd", CITY = "sdsdsdsd" },
new Person() { ID = "kkkkkkk", NAME = "dsdsdsd", CODE = "sdsdsd", CITY = "sdsdsdsd" },
new Person() { ID = "kkkkkkk", NAME = "dsdsdsd", CODE = "sdsdsd", CITY = "sdsdsdsd" },
};
这是我的xml:
<ListView ItemsSource="{Binding CL }" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Label Text="{Binding ID}"></Label>
<Label Text="{Binding NAME}"></Label>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
它在我的页面上没有显示任何内容。
但是当我使用它时,一切正常:
public ObservableCollection<string> trials1 { get; set; } = new ObservableCollection<string> { "One","More","Character" };
我的xaml在这里:
<ListView ItemsSource="{Binding trials1 }" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Label Text="{Binding .}"></Label>
<Label Text="{Binding Length}"></Label>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
解决方案
您只能绑定到公共属性
这不是一个属性 - 它没有获取/设置
public List<Person> CL = new List<Person>() {
这是一个属性
public List<Person> CL { get; set; } = new List<Person>() {
推荐阅读
- ssl - Artifactory jfrog cli:x509:由未知权威签署的证书
- python-3.x - 在类别级别绘制时间序列
- xamarin.forms - 尽管我正确编写了代码,为什么我的应用程序中没有出现广告?
- javascript - 更改图表类型 onclick ChartJS
- python-3.x - 如何使用 discord.py 进行多进程?
- google-apps-script - 即使日期值相同,但无法获取记录器
- r - 如何省略冗余的海量信息?
- macos - 如何使用 macos grep 将文件视为巨大的字符串?
- javascript - 如何在jquery数据表上的下拉选择框中添加删除线并在此基础上过滤掉
- javascript - 解构对象属性和整个对象本身