### Install Sharpnado CollectionView in .NET MAUI Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/Maui/Sharpnado.CollectionView.Maui/ReadMe.md This snippet shows how to install and enable Sharpnado's CollectionView in your .NET MAUI application's core project. It involves modifying the MauiProgram.cs file to include the UseSharpnadoCollectionView extension method. ```csharp public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder .UseMauiApp() .UseSharpnadoCollectionView(loggerEnable: false); } ``` -------------------------------- ### Load Raw Asset using C# and .NET MAUI Essentials Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/Maui/MauiSample/Resources/Raw/AboutAssets.txt This C# code demonstrates how to load a raw asset that has been deployed with the application package. It uses `FileSystem.OpenAppPackageFileAsync` to get a stream to the file and `StreamReader` to read its contents. Ensure the asset file exists in the correct location within the project. ```csharp async Task LoadMauiAsset() { using var stream = await FileSystem.OpenAppPackageFileAsync("AboutAssets.txt"); using var reader = new StreamReader(stream); var contents = reader.ReadToEnd(); } ``` -------------------------------- ### Usage: CarouselView Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/Maui/Sharpnado.CollectionView.Maui/ReadMe.md A basic example of how to implement a carousel view using Sharpnado's CollectionView. This snippet is a placeholder and assumes default configurations for a carousel layout. ```xml ``` -------------------------------- ### Initialize Sharpnado.CollectionView in .NET MAUI Source: https://context7.com/roubachof/sharpnado.collectionview/llms.txt Initializes the Sharpnado.CollectionView library within a .NET MAUI application's startup configuration by calling the UseSharpnadoCollectionView extension method. This setup is typically done in the MauiProgram.cs file. It allows disabling logging and debug logs. ```csharp // MauiProgram.cs using Microsoft.Maui; using Microsoft.Maui.Hosting; public static class MauiProgram { public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder .UseMauiApp() .UseSharpnadoCollectionView(loggerEnable: false, debugLogEnable: false); return builder.Build(); } } ``` -------------------------------- ### Usage: GridView with Drag and Drop Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/Maui/Sharpnado.CollectionView.Maui/ReadMe.md Example of using Sharpnado's GridView for a grid layout. This snippet demonstrates setting the column count, enabling drag and drop, and binding the ItemsSource. It is suitable for displaying items in a fixed grid format. ```xml ``` -------------------------------- ### C# ViewModel for Drag and Drop - Sharpnado CollectionView Source: https://context7.com/roubachof/sharpnado.collectionview/llms.txt Implements the ViewModel for the grid layout, managing the collection of items and handling drag and drop events. It initializes the item list, defines commands for drag start, drag end, and item taps, and updates the item order upon drag completion. ```csharp public class GridViewModel : INotifyPropertyChanged { public ObservableCollection Items { get; set; } public ICommand OnDragStartedCommand { get; } public ICommand OnDragEndedCommand { get; } public ICommand ItemTappedCommand { get; } public GridViewModel() { Items = new ObservableCollection(); for (int i = 1; i <= 30; i++) { Items.Add(new GridItem { Id = i, Name = $"Item {i}", ImageUrl = $"item{i}.png" }); } OnDragStartedCommand = new Command(info => { Debug.WriteLine($"Drag started: from index {info.From} to {info.To}"); }); OnDragEndedCommand = new Command(info => { Debug.WriteLine($"Drag ended: moved from {info.From} to {info.To}"); var item = Items[info.From]; Items.RemoveAt(info.From); Items.Insert(info.To, item); }); ItemTappedCommand = new Command(item => { Debug.WriteLine($"Tapped item: {item.Name}"); }); } } ``` -------------------------------- ### Drag and Drop Bindable Properties for Grid/Vertical Layout Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/README.md Introduces specific BindableProperties related to drag and drop functionality when the CollectionView is using a Grid or Vertical ListLayout. These include commands to signal the start and end of a drag-and-drop operation, and a property to indicate if a drag-and-drop is currently in progress. ```csharp public static readonly BindableProperty DragAndDropStartedCommandProperty = BindableProperty.Create( nameof(DragAndDropStartedCommand), typeof(ICommand), typeof(CollectionView)); public static readonly BindableProperty DragAndDropEndedCommandProperty = BindableProperty.Create( nameof(DragAndDropEndedCommand), typeof(ICommand), typeof(CollectionView)); public static readonly BindableProperty IsDragAndDroppingProperty = BindableProperty.Create( nameof(IsDragAndDropping), typeof(bool), typeof(CollectionView), defaultValue: false); ``` -------------------------------- ### C# Grid Layout Rotation Reveal Animation for CollectionView Source: https://context7.com/roubachof/sharpnado.collectionview/llms.txt An alternative implementation for custom reveal animations, specifically tailored for grid layouts. This example demonstrates fading and rotating items based on the CollectionView's layout orientation. It uses FindByName to access the CollectionView and applies conditional rotation (X for vertical, Y for horizontal). ```csharp // Alternative: Rotation reveal for grid layouts public class GridPageWithAnimation : ContentPage { public GridPageWithAnimation() { InitializeComponent(); var collectionView = this.FindByName("CollectionView"); collectionView.PreRevealAnimationAsync = async (viewCell) => { viewCell.View.Opacity = 0; if (collectionView.CollectionLayout == CollectionViewLayout.Vertical) { viewCell.View.RotationX = 90; } else { viewCell.View.RotationY = -90; } }; collectionView.RevealAnimationAsync = async (viewCell) => { var fadeTask = viewCell.View.FadeTo(1, 250); var rotateTask = collectionView.CollectionLayout == CollectionViewLayout.Vertical ? viewCell.View.RotateXTo(0, 250) : viewCell.View.RotateYTo(0, 250); await Task.WhenAll(fadeTask, rotateTask); }; } } ``` -------------------------------- ### Define MauiAsset Build Action in .csproj Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/Maui/MauiSample/Resources/Raw/AboutAssets.txt This XML snippet shows how to configure the `.csproj` file to include raw assets. The `MauiAsset` Build Action ensures that files in the specified directory are deployed with the application package. `LogicalName` is used to define the path of the asset within the package. ```xml ``` -------------------------------- ### C# Custom Reveal Animations for CollectionView Source: https://context7.com/roubachof/sharpnado.collectionview/llms.txt Defines pre-reveal, main reveal, and post-reveal animations for a CollectionView. The pre-reveal sets initial states, the main reveal animates the item into view, and the post-reveal performs optional cleanup. Assumes use of Sharpnado's CollectionView and Task.WhenAll for concurrent animations. ```csharp public partial class AnimatedListPage : ContentPage { public AnimatedListPage() { InitializeComponent(); // Pre-reveal animation (setup before item becomes visible) CollectionView.PreRevealAnimationAsync = async (viewCell) => { viewCell.View.Opacity = 0; viewCell.View.TranslationX = -50; viewCell.View.Scale = 0.8; }; // Main reveal animation (item becoming visible) CollectionView.RevealAnimationAsync = async (viewCell) => { await Task.WhenAll( viewCell.View.FadeTo(1, 300), viewCell.View.TranslateTo(0, 0, 300, Easing.SpringOut), viewCell.View.ScaleTo(1, 300, Easing.SpringOut) ); }; // Post-reveal animation (optional cleanup after reveal) CollectionView.PostRevealAnimationAsync = async (viewCell) => { await viewCell.View.RotateTo(360, 200, Easing.CubicOut); viewCell.View.Rotation = 0; // Reset rotation }; } } ``` -------------------------------- ### CollectionView Commands and Animation Properties Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/README.md Details properties for imperative control and customization of the CollectionView's behavior. Includes a command to force layout updates, event handlers for layout changes, and delegates for custom pre-reveal, reveal, and post-reveal animations on view cells. Also includes properties for view caching and drag-and-drop enabling. ```csharp /// /// Force the layout of the collection view to be updated. /// Useful if you changed a property that should impact the layout but the layout is not updated. /// public Command UpdateLayout { get; internal set; } = new Command(() => { }); public event EventHandler ListLayoutChanging; public Func PreRevealAnimationAsync { get; set; } public Func RevealAnimationAsync { get; set; } public Func PostRevealAnimationAsync { get; set; } /// In certain scenarios, the first scroll of the list can be smoothen /// by pre-building some views. public int ViewCacheSize { get; set; } = 0; public bool EnableDragAndDrop { get; set; } = false; public SnapStyle SnapStyle { get; set; } = SnapStyle.None; public int ColumnCount { get; set; } = 0; public ScrollSpeed ScrollSpeed { get; set; } = ScrollSpeed.Normal; ``` -------------------------------- ### Initialize Sharpnado.CollectionView in Xamarin.Forms (Core) Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/README.md This code initializes Sharpnado.CollectionView for Xamarin.Forms applications. The Initialize method should be called from the App.xaml.cs file to enable the namespace schema for the collection view. ```csharp public App() { InitializeComponent(); Sharpnado.CollectionView.Initializer.Initialize(true, false); ... } ``` -------------------------------- ### XAML Resource Dictionary for CollectionView Item Templates Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/README.md Provides XAML definitions for `DataTemplate` resources used in a `CollectionView`. It includes templates for a header, a footer, and a group header. Each template is designed to be used with `sho:DraggableViewCell` and defines the visual structure for these distinct item types, including labels, layouts, and activity indicators for the footer. ```xml ``` -------------------------------- ### Initialize Sharpnado.CollectionView in Xamarin.Forms (Android) Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/README.md This code demonstrates the initialization of Sharpnado.CollectionView on Android within the OnCreate method. It needs to be executed before Xamarin.Forms.Forms.Init() and LoadApplication(new App()). ```csharp public override OnCreate(Bundle savedInstanceState) { Initializer.Initialize(); global::Xamarin.Forms.Forms.Init(); LoadApplication(new App()); } ``` -------------------------------- ### Initialize Sharpnado.CollectionView in Xamarin.Forms (iOS) Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/README.md This snippet shows the initialization of Sharpnado.CollectionView on iOS within the FinishedLaunching method. It must be called before Xamarin.Forms.Forms.Init() and LoadApplication(new App()). ```csharp public override bool FinishedLaunching(UIApplication app, NSDictionary options) { Initializer.Initialize(); global::Xamarin.Forms.Forms.Init(); LoadApplication(new App()); } ``` -------------------------------- ### C# ViewModel for Populating CollectionView with Headers, Footers, and Groups Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/README.md Demonstrates a C# ViewModel (`HeaderFooterGroupingPageViewModel`) that loads and processes data to populate a collection view with headers, footers, and grouped items. It uses LINQ for ordering and grouping, and constructs a list of `IDudeItem` which includes custom header, footer, and group header objects along with data items. This ViewModel is designed to work with asynchronous data loading. ```csharp public class HeaderFooterGroupingPageViewModel : ANavigableViewModel { public List SillyPeople { get => _sillyPeople; set => SetAndRaise(ref _sillyPeople, value); } private async Task> LoadSillyPeoplePageAsync(int pageNumber, int pageSize, bool isRefresh) { PageResult resultPage = await _sillyDudeService.GetSillyPeoplePage(pageNumber, pageSize); var dudes = resultPage.Items; if (isRefresh) { SillyPeople = new List(); _listSource = new List(); } var result = new List { new DudeHeader() }; _listSource.AddRange(dudes); foreach (var group in _listSource.OrderByDescending(d => d.SillinessDegree) .GroupBy((dude) => dude.SillinessDegree)) { result.Add(new DudeGroupHeader { StarCount = group.Key}); result.AddRange(group.Select(dude => new SillyDudeVmo(dude, TapCommand))); } result.Add(new DudeFooter()); SillyPeople = result; } } ``` -------------------------------- ### Bindable Properties for CollectionView Layout and Data Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/README.md Defines essential BindableProperties for the CollectionView, including layout options, item source binding, item templates, sizing, spacing, and commands for user interactions like tapping and scrolling. These properties are fundamental for controlling the appearance and behavior of the collection view. ```csharp public static readonly BindableProperty ListLayoutProperty = BindableProperty.Create( nameof(ListLayout), typeof(CollectionViewLayout), typeof(CollectionView), CollectionViewLayout.Linear, propertyChanged: OnListLayoutChanged, propertyChanging: OnListLayoutChanging); public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create( nameof(ItemsSource), typeof(IEnumerable), typeof(CollectionView), default(IEnumerable), BindingMode.TwoWay, propertyChanged: OnItemsSourceChanged); public static readonly BindableProperty InfiniteListLoaderProperty = BindableProperty.Create( nameof(InfiniteListLoader), typeof(IInfiniteListLoader), typeof(CollectionView)); public static readonly BindableProperty ItemTemplateProperty = BindableProperty.Create( nameof(ItemTemplate), typeof(DataTemplate), typeof(CollectionView), default(DataTemplate)); public static readonly BindableProperty ItemHeightProperty = BindableProperty.Create( nameof(ItemHeight), typeof(double), typeof(CollectionView), defaultValue: 0D, defaultBindingMode: BindingMode.OneWayToSource); public static readonly BindableProperty ItemWidthProperty = BindableProperty.Create( nameof(ItemWidth), typeof(double), typeof(CollectionView), defaultValue: 0D, defaultBindingMode: BindingMode.OneWayToSource); public static readonly BindableProperty CollectionPaddingProperty = BindableProperty.Create( nameof(CollectionPadding), typeof(Thickness), typeof(CollectionView), defaultValue: new Thickness(0, 0), defaultBindingMode: BindingMode.OneWayToSource); public static readonly BindableProperty ItemSpacingProperty = BindableProperty.Create( nameof(ItemSpacing), typeof(int), typeof(CollectionView), defaultValue: 0, defaultBindingMode: BindingMode.OneWayToSource); public static readonly BindableProperty TapCommandProperty = BindableProperty.Create( nameof(TapCommand), typeof(ICommand), typeof(CollectionView)); public static readonly BindableProperty ScrollBeganCommandProperty = BindableProperty.Create( nameof(ScrollBeganCommand), typeof(ICommand), typeof(CollectionView)); public static readonly BindableProperty ScrollEndedCommandProperty = BindableProperty.Create( nameof(ScrollEndedCommand), typeof(ICommand), typeof(CollectionView)); public static readonly BindableProperty CurrentIndexProperty = BindableProperty.Create( nameof(CurrentIndex), typeof(int), typeof(CollectionView), defaultValue: -1, defaultBindingMode: BindingMode.TwoWay, propertyChanged: OnCurrentIndexChanged); public static readonly BindableProperty VisibleCellCountProperty = BindableProperty.Create( nameof(VisibleCellCount), typeof(int), typeof(CollectionView), defaultValue: 0, defaultBindingMode: BindingMode.TwoWay, propertyChanged: OnVisibleCellCountChanged); public static readonly BindableProperty DisableScrollProperty = BindableProperty.Create( nameof(DisableScroll), typeof(bool), typeof(CollectionView), defaultValue: false, defaultBindingMode: BindingMode.TwoWay); ``` -------------------------------- ### C# ViewModels for Headers, Footers, and Grouped Items in CollectionView Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/README.md Defines C# interfaces and classes to represent different types of items (header, footer, group header, and regular data items) within a collection view. These models are used to structure data for display, enabling distinct visual representations for headers, footers, and grouped content. The SillyDudeVmo class includes properties for item details and a tap command, suitable for binding to UI elements. ```csharp namespace DragAndDropSample.ViewModels { public interface IDudeItem { } public class DudeHeader : IDudeItem { } public class DudeFooter : IDudeItem { } public class DudeGroupHeader : IDudeItem { public int StarCount { get; set; } public string Text => $"{StarCount} Stars"; } public class SillyDudeVmo : IDudeItem { public SillyDudeVmo(SillyDude dude, ICommand tapCommand) { if (dude != null) { Id = dude.Id; Name = dude.Name; FullName = dude.FullName; Role = dude.Role; Description = dude.Description; ImageUrl = dude.ImageUrl; SillinessDegree = dude.SillinessDegree; SourceUrl = dude.SourceUrl; } TapCommand = tapCommand; } public bool IsMovable { get; protected set; } = true; public ICommand TapCommand { get; set; } public int Id { get; } public string Name { get; } public string FullName { get; } public string Role { get; } public string Description { get; } public string ImageUrl { get; } public double SillinessDegree { get; } public string SourceUrl { get; } public override string ToString() { return $"{FullName} silly degree: {SillinessDegree}"; } } } ``` -------------------------------- ### Drag and Drop Data Structure (C#) Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/README.md This C# code defines the `DragAndDropInfo` class, which is passed as an argument to the `DragAndDropStartCommand` and `DragAndDropEndedCommand` when drag and drop is performed. It contains information about the source and destination of the dragged item, as well as its content. ```csharp public class DragAndDropInfo { public int To { get; } public int From { get; } public object Content { get; } } ``` -------------------------------- ### Initialize Sharpnado.CollectionView in Xamarin.Forms Source: https://context7.com/roubachof/sharpnado.collectionview/llms.txt Initializes the Sharpnado.CollectionView library for Xamarin.Forms applications. This involves calling the Initialize method in the shared App.xaml.cs and platform-specific entry points (AppDelegate.cs for iOS, MainActivity.cs for Android). It allows disabling logging and debug logs. ```csharp // App.xaml.cs (Shared) public partial class App : Application { public App() { InitializeComponent(); Sharpnado.CollectionView.Initializer.Initialize(true, false); MainPage = new MainPage(); } } ``` ```csharp // AppDelegate.cs (iOS) public override bool FinishedLaunching(UIApplication app, NSDictionary options) { Sharpnado.CollectionView.iOS.Initializer.Initialize(); global::Xamarin.Forms.Forms.Init(); LoadApplication(new App()); return base.FinishedLaunching(app, options); } ``` ```csharp // MainActivity.cs (Android) protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Sharpnado.CollectionView.Droid.Initializer.Initialize(); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); LoadApplication(new App()); } ``` -------------------------------- ### Implement Cell Reveal Animations in C# Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/README.md This C# code demonstrates how to implement custom reveal animations for cells in a CollectionView. It sets up animations to fade and rotate cells based on the collection view's layout, providing a dynamic visual effect. ```csharp public partial class GridPage : ContentPage { public GridPage() { InitializeComponent(); CollectionView.PreRevealAnimationAsync = async (viewCell) => { viewCell.View.Opacity = 0; if (CollectionView.CollectionLayout == CollectionViewLayout.Vertical) { viewCell.View.RotationX = 90; } else { viewCell.View.RotationY = -90; } }; CollectionView.RevealAnimationAsync = async (viewCell) => { await viewCell.View.FadeTo(1); if (CollectionView.CollectionLayout == CollectionViewLayout.Vertical) { await viewCell.View.RotateXTo(0); } else { await viewCell.View.RotateYTo(0); } }; } } ``` -------------------------------- ### C# GroupedTemplateSelector for Sharpnado CollectionView Source: https://context7.com/roubachof/sharpnado.collectionview/llms.txt Implements a DataTemplateSelector to dynamically choose templates for headers, group headers, footers, and items in a Sharpnado CollectionView. It defines properties for each template type and overrides the OnSelectTemplate method to return the appropriate DataTemplate based on the data item's type. ```csharp // Template Selector public class GroupedTemplateSelector : DataTemplateSelector { public SizedDataTemplate HeaderTemplate { get; set; } public SizedDataTemplate GroupHeaderTemplate { get; set; } public SizedDataTemplate FooterTemplate { get; set; } public DataTemplate ItemTemplate { get; set; } protected override DataTemplate OnSelectTemplate(object item, BindableObject container) { return item switch { HeaderItem => HeaderTemplate, GroupHeader => GroupHeaderTemplate, FooterItem => FooterTemplate, _ => ItemTemplate }; } } // View Models public interface IListItem { } public class HeaderItem : IListItem { } public class FooterItem : IListItem { } public class GroupHeader : IListItem { public int StarCount { get; set; } public string Text => $"{StarCount} Star Items"; } public class DataItem : IListItem { public string Name { get; set; } } // ViewModel public class GroupedViewModel : INotifyPropertyChanged { public ObservableCollection GroupedItems { get; set; } public GroupedViewModel() { GroupedItems = new ObservableCollection(); BuildGroupedList(); } private void BuildGroupedList() { var items = GetDataItems(); GroupedItems.Add(new HeaderItem()); foreach (var group in items.GroupBy(x => x.Rating)) { GroupedItems.Add(new GroupHeader { StarCount = group.Key }); foreach (var item in group) { ``` -------------------------------- ### Usage: Vertical List with Grouping and Scroll Events Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/Maui/Sharpnado.CollectionView.Maui/ReadMe.md This snippet illustrates using Sharpnado's CollectionView for a vertical list that supports grouping, header/footer templates, and capturing scroll events. It shows how to bind data and handle scroll began/ended commands. ```xml ``` -------------------------------- ### XAML Grid Layout with Drag and Drop - Sharpnado CollectionView Source: https://context7.com/roubachof/sharpnado.collectionview/llms.txt Defines a multi-column grid layout for the Sharpnado CollectionView. It includes a DataTemplate for grid items, enabling drag and drop functionality, specifying layout properties, and binding commands for drag and drop events and item taps. ```xml ``` -------------------------------- ### Usage: HorizontalListView Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/Maui/Sharpnado.CollectionView.Maui/ReadMe.md This snippet shows the basic usage of Sharpnado's HorizontalListView for creating horizontal lists. It represents a straightforward implementation for horizontal scrolling content. ```xml ``` -------------------------------- ### Configure Horizontal List Layout in C# Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/README.md Sets the CollectionView layout to horizontal by default. Allows customization of item dimensions, spacing, and padding. Requires setting the CollectionViewLayout property. ```csharp public CollectionViewLayout CollectionLayout { get; set; } = CollectionViewLayout.Horizontal; ``` -------------------------------- ### Load Font Asset using C# Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/Xamarin.Forms/DragAndDropSample/DragAndDropSample.Android/Assets/AboutAssets.txt Shows how to load a font file directly from the Android application's assets. This function leverages `Typeface.CreateFromAsset`, which takes the asset path as a string argument. Ensure the font file is located in the 'fonts' subdirectory within the raw assets and has the 'AndroidAsset' build action. The input is the font file path, and the output is a `Typeface` object. ```csharp Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); ``` -------------------------------- ### Read Android Asset using C# Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/Xamarin.Forms/DragAndDropSample/DragAndDropSample.Android/Assets/AboutAssets.txt Demonstrates how to read a raw asset file deployed with your Android application. This code accesses the application's assets using the `Assets.Open` method, which requires the asset file to be placed in the designated raw assets directory and assigned the 'AndroidAsset' build action. The input is the filename of the asset, and the output is an `InputStream` object. ```csharp public class ReadAsset : Activity { protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); InputStream input = Assets.Open ("my_asset.txt"); } } ``` -------------------------------- ### Define Reveal Animation Properties in C# Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/README.md These C# properties allow you to define asynchronous functions for controlling the animation of cells before, during, and after they are revealed. They take a ViewCell as input and return a Task. ```csharp public Func PreRevealAnimationAsync { get; set; } public Func RevealAnimationAsync { get; set; } public Func PostRevealAnimationAsync { get; set; } ``` -------------------------------- ### XAML Data Templates for Collection Views Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/README.md Defines XAML DataTemplates for different items within a collection view, including a 'DudeTemplate' and a template with shadow effects. These templates are used to visually represent data items in the collection. ```xml ``` -------------------------------- ### C#: ViewModel for Vertical List with Infinite Loading Source: https://context7.com/roubachof/sharpnado.collectionview/llms.txt Implements the ViewModel for the vertical list, handling data binding, pagination, and item tapping. It uses Sharpnado's Paginator component to manage loading data in pages asynchronously from an IPersonService. The ViewModel includes logic for clearing and adding items to the observable collection. ```csharp using Sharpnado.CollectionView.Paging; public class VerticalListViewModel : INotifyPropertyChanged { private const int PageSize = 20; private readonly IPersonService _personService; public ObservableCollection People { get; set; } public Paginator PeoplePaginator { get; } public ICommand ItemTappedCommand { get; } public VerticalListViewModel(IPersonService personService) { _personService = personService; People = new ObservableCollection(); PeoplePaginator = new Paginator( pageSourceLoader: LoadPeoplePageAsync, pageSize: PageSize, maxItemCount: 500, loadingThreshold: 0.25f); ItemTappedCommand = new Command(person => Debug.WriteLine($"Tapped: {person.Name}")); // Load first page LoadInitialData(); } private async void LoadInitialData() { await PeoplePaginator.LoadPage(1); } private async Task> LoadPeoplePageAsync( int pageNumber, int pageSize, bool isRefresh) { try { var result = await _personService.GetPeoplePageAsync(pageNumber, pageSize); var viewModels = result.Items .Select(p => new PersonViewModel(p, ItemTappedCommand)) .ToList(); if (isRefresh) { People.Clear(); } foreach (var vm in viewModels) { People.Add(vm); } return result; } catch (Exception ex) { Debug.WriteLine($"Error loading page: {ex.Message}"); return PageResult.Empty; } } } public class PageResult { public List Items { get; set; } public int TotalCount { get; set; } public int PageNumber { get; set; } public bool HasMoreItems => Items?.Count > 0; public static PageResult Empty => new PageResult { Items = new List(), TotalCount = 0, PageNumber = 0 }; } ``` -------------------------------- ### ViewModel for Horizontal List Layout (C#) Source: https://context7.com/roubachof/sharpnado.collectionview/llms.txt Provides the ViewModel implementation for the horizontal list layout. It manages the collection of 'Person' objects, handles the current index binding, and defines commands for item taps and scroll events. This C# code supports data binding and INotifyPropertyChanged for UI updates. ```csharp // ViewModel public class HorizontalListViewModel : INotifyPropertyChanged { private ObservableCollection _people; private int _currentIndex; public ObservableCollection People { get => _people; set { _people = value; OnPropertyChanged(); } } public int CurrentIndex { get => _currentIndex; set { _currentIndex = value; OnPropertyChanged(); } } public ICommand ItemTappedCommand { get; } public ICommand ScrollBeganCommand { get; } public ICommand ScrollEndedCommand { get; } public HorizontalListViewModel() { ItemTappedCommand = new Command(person => Debug.WriteLine($"Tapped: {person.Name}")); ScrollBeganCommand = new Command(() => Debug.WriteLine("Scroll began")); ScrollEndedCommand = new Command(() => Debug.WriteLine("Scroll ended")); People = new ObservableCollection { new Person { Name = "John", ImageUrl = "person1.jpg", Description = "Developer" }, new Person { Name = "Jane", ImageUrl = "person2.jpg", Description = "Designer" } }; } } ``` -------------------------------- ### Horizontal List Layout DataTemplate and CollectionView in XAML Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/README.md Defines a DataTemplate for horizontal list items and configures a CollectionView to use this template with horizontal scrolling. Includes item dimensions, padding, and commands for scroll events. Leverages XamEffects for touch interactions. ```xml ... ``` -------------------------------- ### Vertical Layout with Drag and Drop (XAML) Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/README.md This snippet illustrates setting up the CollectionView for a Vertical list layout, also with drag and drop enabled. It includes a DataTemplate for list items and the CollectionView definition. Similar to the grid layout, `IsDragAndDropping` can be used with `DataTrigger` for visual feedback. ```xml ``` -------------------------------- ### XAML Declaration of DataTemplateSelector with SizedDataTemplates Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/README.md Declares and configures the HeaderFooterGroupingTemplateSelector in XAML, assigning specific DataTemplates and sizes to HeaderTemplate, FooterTemplate, and GroupHeaderTemplate. The DudeTemplate is assigned directly. ```xml ``` -------------------------------- ### Carousel Layout in XAML Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/README.md Implements a carousel layout for the CollectionView by setting the `ListLayout` property to `Carousel`. In this mode, `ItemWidth` should not be specified, and `ItemHeight` is computed automatically. Includes `ItemSpacing` and `CollectionPadding` for visual configuration. ```xml ... ``` -------------------------------- ### XAML Templates for Sharpnado CollectionView Sections Source: https://context7.com/roubachof/sharpnado.collectionview/llms.txt Defines XAML DataTemplates for header, group header, footer, and item sections within a Sharpnado CollectionView. It utilizes sho:DraggableViewCell and Frames for layout, with bindings for dynamic content like StarCount and Name. The GroupHeaderTemplate includes an ActivityIndicator for a loading state in the footer. ```xml ``` -------------------------------- ### C# DataTemplateSelector for Grouped Collections Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/README.md Implements a custom DataTemplateSelector in C# to dynamically choose the appropriate DataTemplate for different types of items in a grouped collection view. It handles headers, footers, group headers, and individual items. ```csharp public class HeaderFooterGroupingTemplateSelector: DataTemplateSelector { public SizedDataTemplate HeaderTemplate { get; set; } public SizedDataTemplate FooterTemplate { get; set; } public SizedDataTemplate GroupHeaderTemplate { get; set; } public DataTemplate DudeTemplate { get; set; } protected override DataTemplate OnSelectTemplate(object item, BindableObject container) { switch (item) { case DudeHeader header: return HeaderTemplate; case DudeFooter footer: return FooterTemplate; case DudeGroupHeader groupHeader: return GroupHeaderTemplate; default: return DudeTemplate; } } } ``` -------------------------------- ### Enable Drag and Drop with Pan Gesture on iOS (XAML) Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/README.md Enables drag and drop functionality in Sharpnado CollectionView specifically for iOS, utilizing a pan gesture to initiate the drag. This setting is configured in XAML. ```xml ``` -------------------------------- ### Grid Layout with Column Count in XAML Source: https://github.com/roubachof/sharpnado.collectionview/blob/main/README.md Configures a CollectionView to display items in a grid layout by specifying the `ColumnCount` property. The `ItemWidth` is automatically calculated. This layout uses a `Linear` list layout and requires a `ItemTemplate` and `ItemsSource`. ```xml ```