Xamarin形式listview数据绑定(Xamarin Forms listview databinding)

编程入门 行业动态 更新时间:2024-10-27 01:23:48
Xamarin形式listview数据绑定(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; } }

当我启动应用程序时,我得到的所有内容都是空的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="

本文发布于:2023-07-30 06:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336698.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:绑定   形式   数据   Xamarin   listview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!