Xamarin 表单 ExpandableListView/Syncfusion/CollectionView 问题限制项目
我正在尝试使用任何可扩展列表来限制列表的大小,例如,列表返回 30 个我想要显示的项目 3。但是,我可以选择当他们扩展列表时,其余的项目将显示 27 项。当它折叠时,
我们仍然看到 3 个项目作为原始项目大小设置。 任意代码片段a 到此为止 非常有帮助。谢谢
我试图限制这样的代码大小
foreach (var cusName in CustomerNames)
{
if (counter == 13)
counter = 1;
var contact = new Contact(cusName);
contact.CallTime = CallTime[i];
contact.PhoneImage = ImageSource.FromResource("ExpandableListView.Images.PhoneImage.png", assembly);
contact.ContactImage = ImageSource.FromResource("ExpandableListView.Images.Image" + counter + ".png", assembly);
contact.AddContact = ImageSource.FromResource("ExpandableListView.Images.AddContact.png", assembly);
contact.NewContact = ImageSource.FromResource("ExpandableListView.Images.NewContact.png", assembly);
contact.SendMessage = ImageSource.FromResource("ExpandableListView.Images.SendMessage.png", assembly);
contact.BlockSpan = ImageSource.FromResource("ExpandableListView.Images.BlockSpan.png", assembly);
contact.CallDetails = ImageSource.FromResource("ExpandableListView.Images.CallDetails.png", assembly);
i++;
if (ContactsInfo.Count > 2)
{
ContactsInfo.RemoveAt(2);
}
ContactsInfo.Add(contact);
,事实上,它删除了其余部分,但现在我不知道当单击展开选项
I'm trying to use any expandable list in order to limit the size of the list, for example, the list returns 30 items I want to display 3. However, I'm having the option that when they expand the list the rest of 27 items will display . and when it collapses ,
we still see 3 items as the original item size setup.
Any code snippet a
t this point
is very helpful .Thanks
I tried to limit the size in code like this
foreach (var cusName in CustomerNames)
{
if (counter == 13)
counter = 1;
var contact = new Contact(cusName);
contact.CallTime = CallTime[i];
contact.PhoneImage = ImageSource.FromResource("ExpandableListView.Images.PhoneImage.png", assembly);
contact.ContactImage = ImageSource.FromResource("ExpandableListView.Images.Image" + counter + ".png", assembly);
contact.AddContact = ImageSource.FromResource("ExpandableListView.Images.AddContact.png", assembly);
contact.NewContact = ImageSource.FromResource("ExpandableListView.Images.NewContact.png", assembly);
contact.SendMessage = ImageSource.FromResource("ExpandableListView.Images.SendMessage.png", assembly);
contact.BlockSpan = ImageSource.FromResource("ExpandableListView.Images.BlockSpan.png", assembly);
contact.CallDetails = ImageSource.FromResource("ExpandableListView.Images.CallDetails.png", assembly);
i++;
if (ContactsInfo.Count > 2)
{
ContactsInfo.RemoveAt(2);
}
ContactsInfo.Add(contact);
and in fact , it removes the rest , but now I dont know how to display the rest when the click the expand option
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过更新 SfListView.ItemsSource< 来实现您的要求/a> 在扩展器视图中点击基于布尔属性的事件。
请参阅以下代码片段以获取更多参考,
此外,您可以通过设置 HeightRequest 来根据项目数更新 ListView 的高度,如下所述,
参考示例以实现您的要求此处。
You can achieve your requirement by updating the SfListView.ItemsSource in the expander view tapped event based on Boolean property.
Please refer to the following code snippets for more reference,
Also, you can update the ListView’s height based on the items count by setting the HeightRequest as mentioned below,
Refer the sample to achieve your requirement here.
是的,有很多方法可以实现这个功能。
实现此目的的常见方法是更改 ListView 的
ItemsSource
。在这种情况下,我们可以将ItemsSource
的类型定义为ObservableCollection
,例如(VeggieViewModel
是item的类):您可以参考以下示例代码:
MyViewModel.cs
:MyPage.Xaml
Yes, there are many ways to achieve this function.
A common way to achieve this is to change the
ItemsSource
of the ListView.On this condition, we can define the type ofItemsSource
toObservableCollection
, for example(VeggieViewModel
is the class of item):You can refer to the following sample code:
MyViewModel.cs
:MyPage.Xaml
你可以通过多种方式实现它,我将用简单的方式解释。
在 Contact 类中添加另一个属性 bool IsExpanded = false。
并将前 3 项设置为 true,并根据此属性显示列表项。其余项目默认设置为“false”。一旦您单击展开按钮,请将 IsExpanded 属性全部设置为“true”。所有项目都会自动可见。根据您的要求进行更多定制。
希望这能起作用并适合要求,将其标记为答案。快乐编码:)
You can achieve it in many ways, I will explain in a simple way.
In the Contact class add another property bool IsExpanded = false.
And make it true for the first 3 items and show the list items based on this property. And make "false" for rest of the items by default. As soon as you clicked on expanded button make all of them to "true" for IsExpanded property. Automatically, all items will be visible. Do more customization as per your requirement.
Hope this will work and suits for requirement mark it as Answer. Happy Coding :)