我目前正在遵循本指南:
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; } }当我启动应用程序时,我得到的所有内容都是空的listview,有3个字段,但没有任何内容。
我在哪里做错了?
另外,从我正在工作的页面开始,我无法理解与listview关联的这些字段的含义:
GroupDisplayBinding =“{绑定键}”GroupShortNameBinding =“{绑定键}”
尽管我可以在网络上查看,但我没有找到任何关于它们的参考。
I am currently following this guide:
http://www.morganskinner.com/2015/01/xamarin-forms-contacts-search.html
I am willing to make a contacts page in my app, like the one showed in the pictures there, still something is not working out as it should for me:
I wrote/copied the 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>and now I am trying to "display something", not dinamically loaded (yet), from a list of data.
I declared a class like this:
public class Contact { public string Name { get; set; } public string PhoneNumber { get; set; } } }and now the code behind the xaml is this:
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; } }When I launch the app, all I get anyway is an empty listview, with 3 fields but nothing in it.
Where am I doing wrong?
Also, straight from the page where I am working off, I can't understand the meaning of these Fields associated to the listview:
GroupDisplayBinding="{Binding Key}" GroupShortNameBinding="{Binding Key}"
and as much as I could look around on the web, I coudln't find any reference to both of them.
最满意答案
最可能的问题是您声明FilteredContacts的方式,它应该是一个属性,而不是一个字段。 不包括用于绑定搜索属性的反射机制。
Most likely the problem is with the way you declared FilteredContacts, it should be a property, and not a field. The reflection mechanism used in binding only searches for properties, fields are not included.
更多推荐
Name,Binding,listview,public,电脑培训,计算机培训,IT培训"/> <meta name="
发布评论