From e1d6db21793c905c759a5fd5b76fa805ba7837c6 Mon Sep 17 00:00:00 2001 From: redth Date: Thu, 21 Dec 2023 14:19:47 -0500 Subject: [PATCH 1/5] Try adding expandable items --- Sample/VirtualListViewSample/Section.cs | 22 +++++++++++++++++-- .../VirtualListViewSample/SectionedAdapter.cs | 6 ++--- .../SectionedAdapterPage.xaml | 8 ++++++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Sample/VirtualListViewSample/Section.cs b/Sample/VirtualListViewSample/Section.cs index 27d550e..8ebe8e9 100644 --- a/Sample/VirtualListViewSample/Section.cs +++ b/Sample/VirtualListViewSample/Section.cs @@ -1,6 +1,24 @@ -namespace VirtualListViewSample; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; -public class Section : List +namespace VirtualListViewSample; + +public class Section : List { public string Title { get; set; } } + +public partial class SectionItem : ObservableObject +{ + [ObservableProperty] + string text; + + [ObservableProperty] + bool isDetailVisible; + + [RelayCommand] + void ToggleDetail() + { + IsDetailVisible = !IsDetailVisible; + } +} diff --git a/Sample/VirtualListViewSample/SectionedAdapter.cs b/Sample/VirtualListViewSample/SectionedAdapter.cs index 5d10e11..da36b2c 100644 --- a/Sample/VirtualListViewSample/SectionedAdapter.cs +++ b/Sample/VirtualListViewSample/SectionedAdapter.cs @@ -2,7 +2,7 @@ namespace VirtualListViewSample; -public class SectionedAdapter : VirtualListViewAdapterBase +public class SectionedAdapter : VirtualListViewAdapterBase { public SectionedAdapter(IList
items) : base() { @@ -20,7 +20,7 @@ public override int GetNumberOfSections() public override int GetNumberOfItemsInSection(int sectionIndex) => Items[sectionIndex].Count; - public override string GetItem(int sectionIndex, int itemIndex) + public override SectionItem GetItem(int sectionIndex, int itemIndex) => Items[sectionIndex][itemIndex]; public void AddItem(string sectionTitle, string itemName) @@ -33,7 +33,7 @@ public void AddItem(string sectionTitle, string itemName) Items.Add(section); } - section.Add(itemName); + section.Add(new SectionItem { Text = itemName }); InvalidateData(); } diff --git a/Sample/VirtualListViewSample/SectionedAdapterPage.xaml b/Sample/VirtualListViewSample/SectionedAdapterPage.xaml index 3e7ed68..4d38f02 100644 --- a/Sample/VirtualListViewSample/SectionedAdapterPage.xaml +++ b/Sample/VirtualListViewSample/SectionedAdapterPage.xaml @@ -33,7 +33,13 @@ Padding="4" Background="LightBlue" StrokeShape="{RoundRectangle CornerRadius=10}"> -