界面组件DevExpress WPF中文教程:Grid - 如何创建栏(Bands)? DevExpress WPF拥有120个控件和库将帮助您交付满足甚至超出企业需求的高性能业务应用程序。通过DevExpress WPF能创建有着强大互动功能的XAML基础应用程序这些应用程序专注于当代客户的需求和构建未来新一代支持触摸的解决方案。 无论是Office办公软件的衍伸产品还是以数据为中心的商业智能产品都能通过DevExpress WPF控件来实现。本文将为大家介绍如何使用DevExpress WPF GridControl创建栏Bands欢迎下载最新版组件体验DevExpress新旧版本帮助文档获取可点击这篇文章查看——《界面控件DevExpress v26.1帮助文档大全CHM版本》DevExpress WPF GridControl的TableView和TreeListView允许你将列组织成逻辑组这些组被称为栏bands每个栏bands由栏bands标题和子列组成栏bands标题显示在栏bands子列上方的栏bands面板中。创建栏Bands栏Bands是GridControlBand对象GridControl将其存储在GridControl.Bands集合中在设计时您可以使用GridControl的Quick Actions菜单来添加栏Bands。DevExpress WPF GridControlBand的的Quick Actions菜单允许您添加子栏Bands和列并指定栏Bands的Header属性在XAML中1. 将GridControlBand对象添加到GridControl.Bands集合。2. 使用栏Bands的Header属性指定栏Bands中显示的文本。3. 用GridColumn对象填充栏Bands的Columns集合。4. 指定列设置。XAMLdxg:GridControl ItemsSource{Binding Source} dxg:GridControl.Bands dxg:GridControlBand HeaderProduct dxg:GridColumn FieldNameProductName/ /dxg:GridControlBand dxg:GridControlBand HeaderOrder Info dxg:GridColumn FieldNameCountry/ dxg:GridColumn FieldNameCity/ dxg:GridColumn FieldNameOrderDate/ /dxg:GridControlBand dxg:GridControlBand HeaderPricing dxg:GridColumn FieldNameUnitPrice/ dxg:GridColumn FieldNameQuantity/ /dxg:GridControlBand /dxg:GridControl.Bands /dxg:GridControl在代码中C#// Create band objects and specify their settings: var productBand new GridControlBand(); productBand.Header Product; productBand.Columns.Add(new GridColumn() { FieldName nameof(Product.ProductName) }); var orderBand new GridControlBand(); orderBand.Header Order Info; orderBand.Columns.Add(new GridColumn() { FieldName nameof(Product.Country) }); orderBand.Columns.Add(new GridColumn() { FieldName nameof(Product.City) }); orderBand.Columns.Add(new GridColumn() { FieldName nameof(Product.OrderDate) }); var pricingBand new GridControlBand(); pricingBand.Header Pricing; pricingBand.Columns.Add(new GridColumn() { FieldName nameof(Product.UnitPrice) }); pricingBand.Columns.Add(new GridColumn() { FieldName nameof(Product.Quantity) }); // Add bands to the GridControl: grid.Bands.Add(productBand); grid.Bands.Add(orderBand); grid.Bands.Add(pricingBand);VB.NETDim productBand New GridControlBand() productBand.Header Product productBand.Columns.Add(New GridColumn() With { .FieldName NameOf(Product.ProductName) }) Dim orderBand New GridControlBand() orderBand.Header Order Info orderBand.Columns.Add(New GridColumn() With { .FieldName NameOf(Product.Country) }) orderBand.Columns.Add(New GridColumn() With { .FieldName NameOf(Product.City) }) orderBand.Columns.Add(New GridColumn() With { .FieldName NameOf(Product.OrderDate) }) Dim pricingBand New GridControlBand() pricingBand.Header Pricing pricingBand.Columns.Add(New GridColumn() With { .FieldName NameOf(Product.UnitPrice) }) pricingBand.Columns.Add(New GridColumn() With { .FieldName NameOf(Product.Quantity) }) grid.Bands.Add(productBand) grid.Bands.Add(orderBand) grid.Bands.Add(pricingBand)使用数据注释属性您可以使用数据注释属性将网格列分组为栏Bands1. 将DisplayAttribute应用于数据源中的所有字段。2. 使用DisplayAttribute.GroupName属性来指定栏Bands的标题。3. 将DataControlBase.EnableSmartColumnsGeneration属性设置为true来根据数据注释属性生成列。XAMLdxg:GridControl ItemsSource{Binding Source} AutoGenerateColumnsAddNew EnableSmartColumnsGenerationTrue !-- ... -- /dxg:GridControlC#using System.ComponentModel.DataAnnotations; // ... public class Product { [Display(GroupName Product)] public string ProductName { get; set; } [Display(GroupName Order Info)] public string Country { get; set; } [Display(GroupName Order Info)] public string City { get; set; } [Display(GroupName Pricing)] public double UnitPrice { get; set; } [Display(GroupName Pricing)] public int Quantity { get; set; } [Display(GroupName Order Info)] public DateTime OrderDate { get; set; } }VB.NETImports System.ComponentModel.DataAnnotations ... Public Class Product Display(GroupName:Product) Public Property ProductName As String Display(GroupName:Order Info) Public Property Country As String Display(GroupName:Order Info) Public Property City As String Display(GroupName:Pricing) Public Property UnitPrice As Double Display(GroupName:Pricing) Public Property Quantity As Integer Display(GroupName:Order Info) Public Property OrderDate As DateTime End Class绑定到没有GroupName属性的字段的列显示在第一个栏Bands中。