[英]Xamarin Forms listview databinding
我目前正在遵循本指南:
http://www.morganskinner.com/2015/01/xamarin-forms-contacts-search.html
我愿意在我的应用程序中创建一个联系人页面,就像那里的图片中显示的一样,仍然有些东西不适合我:
我写了/复制了XAML:
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<SearchBar x:Name="search" Placeholder="Search"/>
<ListView x:Name="ProvaView" Grid.Row="1" ItemsSource="{Binding FilteredContacts}" IsGroupingEnabled="true" GroupDisplayBinding="{Binding Key}" GroupShortNameBinding="{Binding Key}">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Name}" TextColor="Black" Detail="{Binding PhoneNumber}" DetailColor="Gray">
</TextCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
而现在我正试图从数据列表中“显示某些东西”,而不是从动态加载(尚未)。
我宣布了这样一个类:
public class Contact
{
public string Name { get; set; }
public string PhoneNumber { get; set; }
}
}
现在xaml背后的代码是这样的:
public partial class ContactsPage : MasterDetailPage
{
public List<Contact> FilteredContacts = new List<Contact>
{
new Contact
{
Name = "Guido",
PhoneNumber = "3292773477"
},
new Contact
{
Name = "Luca",
PhoneNumber = "3472737445"
},
new Contact
{
Name = "Luca",
PhoneNumber = "3472737445"
}
};
public ContactsPage()
{
InitializeComponent();
ProvaView.ItemsSource = FilteredContacts;
}
}
当我启动应用程序时,无论如何我得到的是一个空的列表视图,有3个字段,但没有任何内容。
我哪里做错了?
此外,直接从我正在处理的页面,我无法理解与listview关联的这些字段的含义:
GroupDisplayBinding =“{Binding Key}”GroupShortNameBinding =“{Binding Key}”
尽管我可以在网上浏览一下,但我找不到任何对它们的引用。
很可能问题在于您声明FilteredContacts
的方式,它应该是属性,而不是字段。 绑定中使用的反射机制仅搜索属性,不包括字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.