maui-collectionview
ما الذي تفعله
تُرشد هذه المهارة إلى بناء قوائم وشبكات قابلة للتمرير من البيانات في تطبيقات .NET MAUI باستخدام عنصر CollectionView. وهي موجهة للمطورين الذين يعرضون مجموعات عناصر في تطبيقات الجوال أو سطح المكتب.
متى تستخدمها
- ✓عندما تحتاج إلى قائمة أو شبكة قابلة للتمرير من البيانات في تطبيق .NET MAUI.
- ✓عندما تريد التحديد أو التجميع أو السحب للتحديث أو إجراءات السحب على القائمة.
- ✓عندما تريد تحميل المزيد من العناصر أثناء تمرير المستخدم.
رابط المهارة
https://github.com/dotnet/skills/blob/main/plugins/dotnet-maui/skills/maui-collectionview/SKILL.mdانسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“ابنِ شاشة MAUI تعرض منتجاتي في شبكة من عمودين مع السحب للتحديث ورسالة عند عدم وجود عناصر.”
5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.
كيف تعمل
يستخدم وكيلك CollectionView مع التخطيط المناسب وقالب العنصر، ويضيف الميزات التي يحتاجها الطلب فقط، ويحافظ على عمل الكود الموجود.
المحتوى التقني (ملف SKILL.md الأصلي)
النص الأصلي من المؤلف، مباشرة من GitHub.
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
الأسئلة الشائعة
هل تضيف ميزات لم أطلبها؟
لا. صُممت المهارة للإجابة عما طُلب، لا لإضافة كل الخيارات.
هل تستطيع تجميع العناصر؟
نعم. التجميع من الميزات المشمولة.
ماذا عن التخطيطات الثابتة؟
لعدد ثابت من العناصر، تناسب التخطيطات البسيطة مثل Grid بشكل أفضل.
التفاصيل
الوصف الأصلي من المؤلف
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
الشعبية
- نجوم GitHub
- 5.8k
- الترتيب
- #14584
- الترخيص
- MIT
- آخر تحديث
- 2/11/2026
التعليقات
- …
المزيد من المهارات من هذا المستودع
create-custom-agent
5.8kيساعد وكيلك على إنشاء ملفات وكلاء مخصصين لـVS Code، لكل منهم أدواته وتعليماته وتسليماته إلى وكلاء آخرين.
create-skill
5.8kيساعد وكيلك على إنشاء مهارة وكيل جديدة باسم صالح ووصف محفّز واضح وملف SKILL.md يتبع المعيار.
csharp-scripts
5.8kيساعد وكيلك على تشغيل برنامج C# صغير كملف واحد بأداة سطر أوامر .NET، دون إنشاء مشروع كامل.
dotnet-pinvoke
5.8kيساعد وكيلك على استدعاء مكتبات C أو C++ الأصلية من .NET بشكل صحيح، مع التوقيعات ومعالجة النصوص والذاكرة والمقابض الآمنة.
مهارات مشابهة
android-clean-architecture
280kينظّم وكيلك مشاريع أندرويد بكفاءة، ويبني الشيفرة بطريقة تجعل الصيانة وإضافة الميزات الجديدة أسهل.
compose-multiplatform-patterns
280kيساعد وكيلك على استعمال أنماط Compose Multiplatform وJetpack Compose في مشاريع KMP، وتشمل الحالة والتنقل والتصميم والأداء.
dart-flutter-patterns
280kيساعد وكيلك على كتابة شيفرة تطبيقات Dart وFlutter، باستعمال أنماط حديثة لبناء تطبيقات متينة وسهلة الإدارة.