百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
M

Maui.DataGrid

> 编程语言
开源

Maui 的 DataGrid 组件

339 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

Maui 的 DataGrid 组件

Maui.DataGrid

DataGrid library for .NET MAUI applications.

  • Supported Platforms
  • Requirements
  • Installation
  • Getting Started
  • Features
  • API Reference
  • Obsolete Members
  • Dependencies
  • Building From Source
  • Tip
  • Contributing
  • License

Supported Platforms

The library itself targets net10.0 and contains no platform-specific code, so it runs anywhere .NET MAUI runs. The minimum OS versions below are the ones declared by the sample app in this repository, and are the versions the library is exercised against.

Platform Minimum version Status
Android API 24 (Android 7.0) Built and tested by the sample app
iOS 16.0 Built and tested by the sample app
MacCatalyst 15.0 Built and tested by the sample app
Windows 10.0.19041.0 (targeting 10.0.26100.0) Built and tested by the sample app
Tizen 6.5 Should work; the sample's Tizen target is commented out and not built in CI
Other MAUI platforms — Expected to work, not verified

Windows is only added to the sample's target frameworks when the build host is Windows, so the sample can be restored and built on macOS and Linux without the Windows SDK.

To build the sample for Tizen, uncomment the Tizen target framework in Maui.DataGrid.Sample.csproj and install the Tizen tooling from Tizen.NET.

Requirements

To consume the NuGet package:

  • A .NET MAUI app on .NET 10 (net10.0-android, net10.0-ios, net10.0-maccatalyst, net10.0-windows..., etc.)
  • .NET MAUI 10.0.80 or newer (Microsoft.Maui.Controls)

The package references Microsoft.Maui.Controls with PrivateAssets="all", so it does not force a MAUI version on your app — your app's own MauiVersion is used. No MauiProgram registration or Use...() call is needed; only the XAML namespace (see Getting Started).

To build this repository:

  • .NET SDK 10.0.301 or newer — pinned in global.json with "rollForward": "latestFeature"
  • The .NET MAUI workload: dotnet workload restore
  • Platform SDKs for whichever targets you build (Android SDK, Xcode for iOS/MacCatalyst, Windows SDK for Windows)
  • Optional: Visual Studio 2022 (latest, with the ".NET Multi-platform App UI development" workload) or VS Code with the .NET MAUI extension

RestorePackagesWithLockFile is enabled and RestoreLockedMode is turned on for CI builds, so packages.lock.json must be committed whenever a package reference changes. The library also builds with IsTrimmable and IsAotCompatible, and static analysis is strict (AnalysisLevel=latest-all, EnforceCodeStyleInBuild, StyleCop) — warnings will fail your local build if you introduce them.

Installation

bash
dotnet add package akgul.Maui.DataGrid

Or via the Package Manager console:

powershell
Install-Package akgul.Maui.DataGrid

Getting Started

Add the XAML namespace and declare a DataGrid with its columns:

xaml
 xmlns:dg="clr-namespace:Maui.DataGrid;assembly=Maui.DataGrid"

    
        
            
                
                    
                
            
        
        
        
        
        
            
                
                    
                    
                
            
        
        
        
            
                
                    
                        
                    
                
            
        
    
    
        
            #F2F2F2
            #FFFFFF
        
    

A complete, runnable example lives in Maui.DataGrid.Sample — see MainPage.xaml.

Features

Columns and cells

PropertyName supports nested property paths, resolved by reflection against the runtime type of each intermediate value:

xaml

Width accepts the same units as Grid: absolute (120), star (0.5*), or Auto. An Auto column is sized to the widest of its header cell and the cells of the rows currently on screen, and the header and every row are given that one width. Only the realized rows are measured, so scrolling to a longer value widens the column at that point rather than in advance; use an absolute width where that shift is unwelcome.

Use StringFormat for simple formatting, or CellTemplate for arbitrary content. Without a CellTemplate, a cell renders as a Label bound to PropertyName.

CellTemplate and EditCellTemplate also accept a DataTemplateSelector, which is resolved per row — SelectTemplate receives the row's item — so a cell's content can vary with its data.

Cells are created once per on-screen row and reused as rows are recycled while scrolling, so cell content should get everything it displays from its bindings rather than from work done when the template is instantiated. A DataTemplateSelector is re-consulted whenever a row is recycled, and its cell is rebuilt only if the selector picks a different template for the new item.

The default header style truncates a title too long for its column, so each header carries a tooltip of its own title. Override it with HeaderToolTip, or set HeaderToolTip="" for a header with no tooltip:

xaml

Note that ToolTipProperties.Text cannot be used on a column instead: a DataGridColumn is not a view and never enters the visual tree, so an attached property set on one has nothing to attach to.

Sorting

Sorting is enabled by default (DataGrid.SortingEnabled), and each column can opt out with DataGridColumn.SortingEnabled="False". A column's underlying type must implement IComparable to be sortable; DataGridColumn.IsSortable() reports whether it does.

SortedColumnIndex is a SortData (index + SortingOrder) and is two-way bindable. An int implicitly converts to SortData, where a negative index means a descending sort:

xaml

Filtering

Set DataGrid.FilteringEnabled="True" to show a filter Entry in each header cell. Individual columns can opt out with DataGridColumn.FilteringEnabled="False", and DataGridColumn.FilterText is bindable so filters can be driven or read from a view model. Changing a filter resets PageNumber to 1.

Pagination

Set PaginationEnabled="True" to show the pagination footer. PageSize defaults to 100, must be greater than zero, and the page-size picker offers 5, 10, 50, 100, 200, 1000 unless you supply your own PageSizeList. PageCount is read-only (OneWayToSource). PageText and PerPageText exist so the footer labels can be localized, and PageSizeVisible="False" hides the page-size picker.

Selection

SelectionMode (None, Single, Multiple) replaces the obsolete SelectionEnabled. Use SelectedItem for Single and SelectedItems for Multiple — switching modes clears the one that no longer applies. Both are coerced against the grid's current items, so a selection that is not present in ItemsSource is dropped.

ItemSelected (event) fires on selection change. RowTappedCommand does too by default, receiving the SelectionChangedEventArgs — which means it does not fire when the already-selected row is tapped again, nor at all while SelectionMode="None". Set RowTappedCommandMode="Tap" to have every row tap execute the command with the tapped item as its parameter instead, regardless of SelectionMode:

xaml

In Tap mode the command is not executed from the selection-change path, so a tap executes it exactly once. RowTappedCommandMode defaults to SelectionChanged for backwards compatibility; the default is expected to change in the next major version.

Editing

Bind RowToEdit to the item that should render in edit mode. Cells in that row use DataGridColumn.EditCellTemplate (default: an Entry bound to PropertyName) instead of CellTemplate.

Pull to refresh

Bind PullToRefreshCommand (optionally with PullToRefreshCommandParameter) and IsRefreshing. RefreshingEnabled toggles the gesture, RefreshColor sets the spinner color, and the Refreshing event is raised when a refresh starts.

Row colors

RowsBackgroundColorPalette and RowsTextColorPalette take any IColorProvider. PaletteCollection is the built-in implementation and cycles its colors across rows. Implement IColorProvider yourself for data-driven colors:

csharp
internal sealed class OverdueColorProvider : IColorProvider
{
    public Color GetColor(int rowIndex, object item) =>
        item is Invoice { IsOverdue: true } ? Colors.MistyRose : Colors.White;
}

ActiveRowColor is the color of the selected row.

GetColor is re-evaluated for every visible row whenever the displayed items change — adding, removing, sorting, filtering, or changing page — so a row's color always matches its current index.

Empty state

NoDataView is shown when the grid has no rows (it maps to the underlying CollectionView's EmptyView).

Scrolling

csharp
dataGrid.ScrollTo(item, ScrollToPosition.MakeVisible, animated: true);

Threading

An ItemsSource collection may be added to, removed from, or cleared on any thread — the grid marshals the resulting sort, filter, and pagination work to the UI thread itself, so a background worker filling a collection needs no MainThread.BeginInvokeOnMainThread of its own. Note that this covers mutations of the collection only: the grid's properties, ItemsSource included, must be set on the UI thread like those of any other MAUI control.

Styling

HeaderLabelStyle, HeaderFilterStyle, SortIconStyle, and PaginationStepperStyle override the grid's defaults; the first three can also be set per column. Setting one of them back to null restores the built-in default. BorderColor, BorderThickness, HeaderBordersVisible, HeaderBackground, FooterBackground, FooterTextColor, FontFamily, and FontSize cover the rest of the chrome.

Borders are not drawn as outlines: each cell is inset by half of BorderThickness over a surface painted in BorderColor, and the surface showing through those insets is what looks like a grid line. So BorderColor is the grid line colour, and BorderThickness="0" removes the surface along with the lines — set it to zero (or HeaderBordersVisible="False" for the header alone) to see the grid's own background through the rows.

API Reference

DataGrid

All of the following are bindable properties.

Property Type Default Description
ItemsSource IEnumerable null Rows to display. INotifyCollectionChanged sources are observed for changes.
Columns ObservableCollection empty Column definitions.
SelectionMode SelectionMode Single None, Single, or Multiple. Two-way.
SelectedItem object? null Selected row in Single mode. Two-way.
SelectedItems IList empty Selected rows in Multiple mode. Two-way.
RowTappedCommand ICommand null Executed on row tap. Parameter and trigger depend on RowTappedCommandMode.
RowTappedCommandMode RowTappedCommandMode SelectionChanged SelectionChanged passes SelectionChangedEventArgs on selection change; Tap passes the tapped item on every tap.
RowToEdit object null Row rendered using EditCellTemplate.
SortingEnabled bool true Enables sorting for the grid.
SortedColumnIndex SortData? null Current sort. Two-way. Negative int means descending.
SortIcon Polygon null Custom sort indicator shape.
SortIconStyle Style built-in Style for the sort indicator.
FilteringEnabled

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C#androiddatagriddatagrid-componentdatagridview

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言