Loading...
Loading...
Compare original and translation side by side
<Grid DataContext="{x:Bind ViewModel}"><Grid DataContext="{x:Bind ViewModel}">Syncfusion.UI.Xaml.DataGrid.SfDataGridSyncfusion.Grid.WinUISyncfusion.GridExport.WinUISyncfusion.XlsIO.NETSyncfusion.UI.Xaml.DataGridSyncfusion.UI.Xaml.DataGrid.SfDataGridSyncfusion.Grid.WinUISyncfusion.GridExport.WinUISyncfusion.XlsIO.NETSyncfusion.UI.Xaml.DataGrid<!-- MainPage.xaml -->
<Page xmlns:dataGrid="using:Syncfusion.UI.Xaml.DataGrid">
<Grid>
<dataGrid:SfDataGrid x:Name="sfDataGrid"
ItemsSource="{Binding Orders}"
AutoGenerateColumns="True"
AllowSorting="True"
AllowFiltering="True"
AllowEditing="True"
SelectionMode="Single" />
</Grid>
</Page>// MainPage.xaml.cs
using Microsoft.UI.Xaml.Controls;
using System.Collections.ObjectModel;
public sealed partial class MainPage : Page
{
public ObservableCollection<Order> Orders { get; set; }
public MainPage()
{
this.InitializeComponent();
Orders = new ObservableCollection<Order>
{
new Order { OrderID = 1001, CustomerName = "Maria Anders", Country = "Germany", Total = 250.50M },
new Order { OrderID = 1002, CustomerName = "Ana Trujillo", Country = "Mexico", Total = 180.00M },
new Order { OrderID = 1003, CustomerName = "Antonio Moreno", Country = "Mexico", Total = 420.75M }
};
sfDataGrid.ItemsSource = Orders;
}
}
// Order Model
public class Order
{
public int OrderID { get; set; }
public string CustomerName { get; set; }
public string Country { get; set; }
public decimal Total { get; set; }
}<!-- MainPage.xaml -->
<Page xmlns:dataGrid="using:Syncfusion.UI.Xaml.DataGrid">
<Grid>
<dataGrid:SfDataGrid x:Name="sfDataGrid"
ItemsSource="{Binding Orders}"
AutoGenerateColumns="True"
AllowSorting="True"
AllowFiltering="True"
AllowEditing="True"
SelectionMode="Single" />
</Grid>
</Page>// MainPage.xaml.cs
using Microsoft.UI.Xaml.Controls;
using System.Collections.ObjectModel;
public sealed partial class MainPage : Page
{
public ObservableCollection<Order> Orders { get; set; }
public MainPage()
{
this.InitializeComponent();
Orders = new ObservableCollection<Order>
{
new Order { OrderID = 1001, CustomerName = "Maria Anders", Country = "Germany", Total = 250.50M },
new Order { OrderID = 1002, CustomerName = "Ana Trujillo", Country = "Mexico", Total = 180.00M },
new Order { OrderID = 1003, CustomerName = "Antonio Moreno", Country = "Mexico", Total = 420.75M }
};
sfDataGrid.ItemsSource = Orders;
}
}
// Order Model
public class Order
{
public int OrderID { get; set; }
public string CustomerName { get; set; }
public string Country { get; set; }
public decimal Total { get; set; }
}<dataGrid:SfDataGrid x:Name="sfDataGrid"
AutoGenerateColumns="False"
ItemsSource="{Binding Orders}">
<dataGrid:SfDataGrid.Columns>
<dataGrid:GridTextColumn MappingName="OrderID"
HeaderText="Order ID"
Width="120" />
<dataGrid:GridTextColumn MappingName="CustomerName"
HeaderText="Customer"
Width="200" />
<dataGrid:GridTextColumn MappingName="Country"
Width="150" />
<dataGrid:GridNumericColumn MappingName="Total"
HeaderText="Total Amount"
Width="150" />
</dataGrid:SfDataGrid.Columns>
</dataGrid:SfDataGrid><dataGrid:SfDataGrid x:Name="sfDataGrid"
AutoGenerateColumns="False"
ItemsSource="{Binding Orders}">
<dataGrid:SfDataGrid.Columns>
<dataGrid:GridTextColumn MappingName="OrderID"
HeaderText="Order ID"
Width="120" />
<dataGrid:GridTextColumn MappingName="CustomerName"
HeaderText="Customer"
Width="200" />
<dataGrid:GridTextColumn MappingName="Country"
Width="150" />
<dataGrid:GridNumericColumn MappingName="Total"
HeaderText="Total Amount"
Width="150" />
</dataGrid:SfDataGrid.Columns>
</dataGrid:SfDataGrid><dataGrid:SfDataGrid x:Name="sfDataGrid"
ItemsSource="{Binding Orders}"
AllowSorting="True"
AllowFiltering="True"
FilterRowPosition="FixedTop"
AllowTriStateSorting="True" /><dataGrid:SfDataGrid x:Name="sfDataGrid"
ItemsSource="{Binding Orders}"
AllowSorting="True"
AllowFiltering="True"
FilterRowPosition="FixedTop"
AllowTriStateSorting="True" /><dataGrid:SfDataGrid x:Name="sfDataGrid"
ItemsSource="{Binding Orders}"
AllowGrouping="True"
ShowGroupDropArea="True" />// Programmatic grouping
sfDataGrid.GroupColumnDescriptions.Add(new GroupColumnDescription { ColumnName = "Country" });<dataGrid:SfDataGrid x:Name="sfDataGrid"
ItemsSource="{Binding Orders}"
AllowGrouping="True"
ShowGroupDropArea="True" />// 程序化分组
sfDataGrid.GroupColumnDescriptions.Add(new GroupColumnDescription { ColumnName = "Country" });<dataGrid:SfDataGrid x:Name="sfDataGrid"
ItemsSource="{Binding Orders}"
AllowEditing="True"
EditTrigger="OnDoubleTap"
NavigationMode="Cell" /><dataGrid:SfDataGrid x:Name="sfDataGrid"
ItemsSource="{Binding Orders}"
AllowEditing="True"
EditTrigger="OnDoubleTap"
NavigationMode="Cell" /><dataGrid:SfDataGrid x:Name="sfDataGrid"
ItemsSource="{Binding Orders}"
ShowRowHeader="True">
<dataGrid:SfDataGrid.TableSummaryRows>
<dataGrid:GridTableSummaryRow ShowSummaryInRow="False">
<dataGrid:GridTableSummaryRow.SummaryColumns>
<dataGrid:GridSummaryColumn Name="TotalSum"
MappingName="Total"
SummaryType="DoubleAggregate"
Format="'Total: {Sum:C}'" />
<dataGrid:GridSummaryColumn Name="OrderCount"
MappingName="OrderID"
SummaryType="CountAggregate"
Format="'Count: {Count}'" />
</dataGrid:GridTableSummaryRow.SummaryColumns>
</dataGrid:GridTableSummaryRow>
</dataGrid:SfDataGrid.TableSummaryRows>
</dataGrid:SfDataGrid><dataGrid:SfDataGrid x:Name="sfDataGrid"
ItemsSource="{Binding Orders}"
ShowRowHeader="True">
<dataGrid:SfDataGrid.TableSummaryRows>
<dataGrid:GridTableSummaryRow ShowSummaryInRow="False">
<dataGrid:GridTableSummaryRow.SummaryColumns>
<dataGrid:GridSummaryColumn Name="TotalSum"
MappingName="Total"
SummaryType="DoubleAggregate"
Format="'Total: {Sum:C}'" />
<dataGrid:GridSummaryColumn Name="OrderCount"
MappingName="OrderID"
SummaryType="CountAggregate"
Format="'Count: {Count}'" />
</dataGrid:GridTableSummaryRow.SummaryColumns>
</dataGrid:GridTableSummaryRow>
</dataGrid:SfDataGrid.TableSummaryRows>
</dataGrid:SfDataGrid>| Property | Type | Description |
|---|---|---|
| | Data source for the grid (IEnumerable) |
| | Auto-create columns from data source properties |
| | Collection of manually defined columns |
| | Enable/disable sorting (default: false) |
| | Enable/disable filtering (default: false) |
| | Enable/disable grouping (default: false) |
| | Enable/disable editing (default: false) |
| | Single, Multiple, Extended, None |
| | Row or Cell |
| | Cell or Row navigation |
| | None, Star, Auto, SizeToCells, SizeToHeader, AutoLastColumnFill, AutoWithLastColumnFill |
| | Show drag-and-drop area for grouping |
| | FixedTop, Top, Bottom |
| 属性 | 类型 | 描述 |
|---|---|---|
| | 网格的数据源(IEnumerable类型) |
| | 是否从数据源属性自动创建列 |
| | 手动定义的列集合 |
| | 启用/禁用排序(默认:false) |
| | 启用/禁用筛选(默认:false) |
| | 启用/禁用分组(默认:false) |
| | 启用/禁用编辑(默认:false) |
| | 单选、多选、扩展选择、无选择 |
| | 选择单位:行或单元格 |
| | 导航模式:单元格或行导航 |
| | None、Star、Auto、SizeToCells、SizeToHeader、AutoLastColumnFill、AutoWithLastColumnFill |
| | 是否展示分组拖拽区域 |
| | 筛选行位置:FixedTop、Top、Bottom |
// ViewModel
public class OrderViewModel : INotifyPropertyChanged
{
private ObservableCollection<Order> orders;
private Order selectedOrder;
public ObservableCollection<Order> Orders
{
get => orders;
set { orders = value; OnPropertyChanged(); }
}
public Order SelectedOrder
{
get => selectedOrder;
set { selectedOrder = value; OnPropertyChanged(); }
}
public ICommand DeleteCommand { get; }
public ICommand ExportCommand { get; }
}<!-- View -->
<dataGrid:SfDataGrid ItemsSource="{Binding Orders}"
SelectedItem="{Binding SelectedOrder, Mode=TwoWay}" />// ViewModel
public class OrderViewModel : INotifyPropertyChanged
{
private ObservableCollection<Order> orders;
private Order selectedOrder;
public ObservableCollection<Order> Orders
{
get => orders;
set { orders = value; OnPropertyChanged(); }
}
public Order SelectedOrder
{
get => selectedOrder;
set { selectedOrder = value; OnPropertyChanged(); }
}
public ICommand DeleteCommand { get; }
public ICommand ExportCommand { get; }
}<!-- View -->
<dataGrid:SfDataGrid ItemsSource="{Binding Orders}"
SelectedItem="{Binding SelectedOrder, Mode=TwoWay}" />AutoGenerateColumns="False"ColumnWidthMode="None"ItemsSourceDataContextAllowEditing="True"NavigationMode="Cell"AllowEditing="True"ColumnWidthMode="None"AllowSorting="True"AllowFiltering="True"ItemsSourceDataContextAllowEditing="True"NavigationMode="Cell"AllowEditing="True"ColumnWidthMode="None"AllowSorting="True"AllowFiltering="True"