maui-collectionview
Skill này làm gì
Skill này hướng dẫn xây dựng danh sách và lưới dữ liệu cuộn được trong ứng dụng .NET MAUI bằng control CollectionView. Skill dành cho lập trình viên hiển thị tập hợp các mục trong ứng dụng di động hoặc desktop.
Khi nào nên dùng
- ✓Khi bạn cần một danh sách hoặc lưới dữ liệu cuộn được trong ứng dụng .NET MAUI.
- ✓Khi bạn muốn chọn, nhóm, kéo để làm mới hoặc vuốt thao tác trên danh sách.
- ✓Khi bạn muốn tải thêm mục khi người dùng cuộn.
Liên kết skill
https://github.com/dotnet/skills/blob/main/plugins/dotnet-maui/skills/maui-collectionview/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Xây dựng màn hình MAUI hiển thị sản phẩm của tôi dưới dạng lưới hai cột, có kéo để làm mới và thông báo khi trống.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent dùng CollectionView với bố cục và item template phù hợp, chỉ thêm các tính năng mà yêu cầu cần, và giữ cho code hiện có vẫn hoạt động.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
CollectionView — .NET MAUI
CollectionView is the primary control for displaying scrollable lists and grids of data in .NET MAUI. It replaces ListView with better performance, flexible layouts, and no ViewCell requirement.
When to Use
- Displaying a scrollable list or grid of data items
- Binding a collection of objects to a templated item layout
- Adding selection (single or multiple), grouping, or pull-to-refresh
- Implementing infinite scroll / incremental loading
- Showing swipe actions on list items
- Displaying an empty state when no data is available
When Not to Use
- Static layouts with a fixed number of items — use
GridorStackLayoutdirectly - Map pin lists — use the
Microsoft.Maui.Controls.MapsNuGet package - Table-based data entry forms — use standard form controls
- Simple text-only lists with no interaction — consider
BindableLayouton aStackLayout
Scope Control — Answer Only What Was Asked
This skill is a reference you consult, not a checklist you apply. Most requests need one or two sections from it. Pulling in the rest makes the answer worse.
Stop conditions — do NOT act when:
- The user asked a narrow question. Answer that question only. Do not append grouping, swipe actions, empty views, snap points, or performance tips that were not asked about.
- The user's existing code already works. Do not rewrite working markup to match the examples here. Point out a concrete defect; if there is none, say so and answer the question that was asked.
- The change is stylistic. Renaming, reordering attributes, or restructuring a template that already behaves correctly is churn, not a fix.
- The control isn't
CollectionView.CarouselView,BindableLayout, andListView-in-maintenance code have different rules. Do not rewriteListViewcode the user did not ask about — but if they ask which control to use, or are migrating from Xamarin.Forms, recommendCollectionView(see Migrating from ListView). - The problem is really a binding, DI, or navigation problem that happens to
involve a list — defer to
maui-data-binding,maui-dependency-injection, ormaui-shell-navigation.
The API sections below are a reference, not a checklist — offer them only when relevant. Four rules are non-negotiable, because violating them produces code that does not work or silently loses compile-time checking:
- Never use
ViewCellas aDataTemplateroot inCollectionView. - Use
ObservableCollection<T>when the list mutates after first render. - Mutate the bound collection on the UI thread.
- Set
x:DataTypeon everyDataTemplate(and on the page root) for compiled bindings.
Everything else — sizing strategy, snap points, header/footer, empty views — is optional and should be offered only when it addresses the user's actual problem.
Inputs
- A data source (typically
ObservableCollection<T>) bound toItemsSource - A
DataTemplatedefining how each item renders - Optional: layout configuration, selection mode, grouping model, empty view
Basic Setup
A complete, copy-pasteable page. Two things are load-bearing: the xmlns:models
declaration that every x:DataType="models:Item" in this skill assumes, and the
root x:DataType — without it the outer ItemsSource binding is not compiled:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:models="clr-namespace:MyApp.Models"
xmlns:vm="clr-namespace:MyApp.ViewModels"
x:DataType="vm:ItemsViewModel"
x:Class="MyApp.ItemsPage">
<ContentPage.BindingContext>
<vm:ItemsViewModel />
</ContentPage.BindingContext>
<CollectionView ItemsSource="{Binding Items}">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="models:Item">
<HorizontalStackLayout Padding="8" Spacing="8">
<Image Source="{Binding Icon}" WidthRequest="40" HeightRequest="40" />
<Label Text="{Binding Name}" VerticalOptions="Center" />
</HorizontalStackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</ContentPage>
Later snippets show only the CollectionView element. When you hand a snippet to a
user, include the matching xmlns: declaration for any prefix it uses
Câu hỏi thường gặp
Skill có thêm tính năng tôi không yêu cầu không?
Không. Skill chỉ trả lời đúng câu hỏi, không thêm mọi tùy chọn có sẵn.
Có thể nhóm các mục không?
Có. Nhóm là một trong các tính năng được bao quát.
Còn bố cục tĩnh thì sao?
Với số lượng mục cố định, các bố cục đơn giản như Grid phù hợp hơn.
Chi tiết
Mô tả gốc của tác giả
Guidance for implementing CollectionView in .NET MAUI apps — data display, layouts (list & grid), selection, grouping, scrolling, empty views, templates, incremental loading, swipe actions, and pull-to-refresh. USE FOR: "CollectionView", "list view", "grid layout", "data template", "item template", "grouping", "pull to refresh", "incremental loading", "swipe actions", "empty view", "selection mode", "scroll to item", displaying scrollable data, replacing ListView. DO NOT USE FOR: simple static layouts without scrollable data (use Grid or StackLayout), map pin lists (use Microsoft.Maui.Controls
repo: dotnet/skills
Độ phổ biến
- Sao GitHub
- 5.8k
- Vị trí xếp hạng
- #14584
- Giấy phép
- MIT
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
create-custom-agent
5.8kGiúp agent của bạn tạo file custom agent cho VS Code, với các tool, hướng dẫn và handoff riêng sang agent khác.
create-skill
5.8kGiúp agent của bạn tạo một agent skill mới với tên hợp lệ, mô tả kích hoạt rõ ràng và file SKILL.md đúng tiêu chuẩn.
csharp-scripts
5.8kGiúp agent của bạn chạy một chương trình C# nhỏ dưới dạng một file duy nhất bằng công cụ dòng lệnh .NET, không cần tạo project đầy đủ.
dotnet-pinvoke
5.8kGiúp agent của bạn gọi các thư viện native C hoặc C++ từ .NET đúng cách, gồm khai báo chữ ký, xử lý chuỗi, bộ nhớ và safe handle.
Skill tương tự
android-clean-architecture
280kGiúp agent của bạn tổ chức dự án Android hiệu quả, cấu trúc code để việc bảo trì và phát triển tính năng mới dễ dàng hơn.
compose-multiplatform-patterns
280kGiúp agent của bạn dùng các mẫu Compose Multiplatform và Jetpack Compose trong dự án KMP, gồm trạng thái, điều hướng, giao diện và hiệu năng.
dart-flutter-patterns
280kGiúp agent của bạn viết code cho ứng dụng Dart và Flutter. Agent dùng các mẫu hiện đại để tạo ứng dụng vững chắc và dễ quản lý.