列的概述

您可以通过使用控件的columns集合在RadDataGrid中添加列。通常,有三种方法可以定义不同的列:

Xamarin忍者图像的Telerik UI

专栏是Xamarin的Telerik UI,一个专业级的UI组件库,用于构建现代和功能丰富的 应用程序。想要试用它,可以注册一个30天的免费试用期。

  • 手动类型中添加列RadDataGrid。列集合
  • 自动:通过设置RadDataGrid。AutoGenerateColumns = " True "
  • 混合类型中添加列RadDataGrid。列Collection和setRadDataGrid。AutoGenerateColumns = " True "

RadDataGrid控件提供以下类型的列:

  • 文本列:表示将每个关联单元格的内容转换为系统的列。字符串对象。
  • 数值列:表示一个扩展的DataGridTextColumn,它表示数值数据(int和double类型)。
  • 布尔列:表示布尔数据的特殊DataGridTypedColumn实现。
  • 日期列:显示DateTime类型数据的扩展DataGridTextColumn。
  • 时间列控件的扩展DataGridTextColumnTimeOfDayDateTime类型。
  • 选择列:表示一个扩展的DataGridTextColumn,它使用Picker编辑器从集合中选择值。
  • 模板列:表示使用DataTemplate描述每个关联网格单元格内容的列。

当RadDataGrid。AutoGenerateColumns="True" RadDataGrid根据底层数据类型生成类型化列。

属性

类的所有类型的列都继承自DataGridColumn类,它提供以下属性:

  • HeaderText(字符串):获取或设置要在表示列的Header UI中显示的内容。
  • HeaderStyle(DataGridColumnHeaderStyle):获取或设置定义DataGridColumnHeader控件外观的Style实例。
  • HeaderContentTemplate(DataTemplate):获取或设置定义标头外观的DataTemplate实例。
  • SizeMode(DataGridColumnSizeMode):获取或设置DataGridColumnSizeMode值,该值控制列及其相关单元格的水平大小。
    • 固定:列具有固定的宽度,由其width属性定义。
    • 拉伸:将列拉伸到与其所需宽度成比例的可用宽度。
    • 自动:列的大小为其所需的宽度。这是所有相关单元格所需的最大宽度。
  • 宽度(double): -获取或设置列的固定宽度。当SizeMode属性设置为datagridcolumnsizemode时适用。
  • ActualWidth(double):获取列的实际宽度。
  • IsAutoGenerated(bool):获取一个值,该值指示该列是否在内部自动生成。
  • CanUserEdit(bool):获取或设置一个值,该值指示用户是否可以编辑此列中的值。
  • CanUserGroup(bool):获取或设置一个值,该值指示用户是否可以使用内置的Grouping UI根据该列进行分组。
  • CanUserFilter(bool):获取或设置一个值,该值指示用户是否可以使用内置的Filtering UI筛选该列。
  • CanUserSort(bool):获取或设置一个值,该值指示用户是否可以根据该列中的值对数据进行排序。
  • IsVisible(bool):获取一个值,该值指示是否应该显示特定的列。
  • CellDecorationStyle(DataGridBorderStyle):定义Style对象,该对象定义与此列关联的每个单元格的背景。
  • CellDecorationStyleSelector(DataGridStyleSelector):定义允许在每个单元格基础上动态装饰的StyleSelector实例。
  • CellContentTemplate(DataTemplate):定义与具体列关联的每个单元格的外观。
  • CellEditTemplate(DataTemplate):定义与具体列关联的编辑器。当单元格处于编辑模式时,将显示CellEditTemplate。
  • FilterControlTemplate(DataTemplate):用于过滤UI的用户定义模板。模板必须包含Telerik.XamarinForms.DataGrid.DataGridFilterControlBase类的实例

CellContentTemplateCellEditTemplate而且FilterControlTemplate属性是R2 2020官方发布的DataGrid特性的一部分。有关cellledit和单元格内容模板特性的详细信息,请查看细胞模板篇文章。有关过滤器控制模板的更多详细信息,请参阅FilterControl模板部分。

更多关于CellDecorationStyle而且CellDecorationStyleSelector可在列的样式的话题。

为了启用RadDataGrid单元格的用户编辑模式,请设置RadDataGrid。UserEditMode = "电池"

DataGrid列的示例

下面的示例包含RadDataGrid控件提供的所有类型的列。

使用下面的代码片段在XAML中声明一个RadDataGrid:

                       

在哪里telerikDataGrid命名空间如下:

xmlns: telerikDataGrid = " clr-namespace: Telerik.XamarinForms.DataGrid;装配= Telerik.XamarinForms.DataGrid”

视图模型类的声明如下:

public class ColumnsViewModel {private ObservableCollection clubs;public observablecollect  Clubs => Clubs ??(clubs = CreateClubs());私人ObservableCollection <俱乐部> CreateClubs(){返回新ObservableCollection <俱乐部>{新俱乐部(“英国利物浦新DateTime(1892、1、1),新DateTime(3 2018、2、22日,28日,33),45362年,“英格兰”),新俱乐部(“对曼联。”、新DateTime(1878、1、1),新DateTime(2018、1、1、2、56岁44),76212年,“英格兰”){IsChampion = true},新俱乐部(“切尔西”,新DateTime(1905、1、1),新DateTime(6 2018 6, 17日,19日,59岁),42055年,“英格兰”),新俱乐部(“巴塞罗那”,新DateTime(1899、1、1),new DateTime(2018, 7,12,12,25,31), 99354, "西班牙")};}}

俱乐部自定义对象:

public class Club: INotifyPropertyChanged{私有字符串名称;私有DateTime建立;私有DateTime时间;私人体育场容量;private bool是否是champion;私弦国;public Club(string name, DateTime established, DateTime time time, int stadiumCapacity, string country) {name = name;已建立的;时间=时间;体育场容量=体育场容量; Country = country; } public string Name { get { return this.name; } set { this.UpdateValue(ref this.name, value); } } public DateTime Established { get { return this.established; } set { this.UpdateValue(ref this.established, value); } } public DateTime Time { get { return this.time; } set { this.UpdateValue(ref this.time, value); } } public int StadiumCapacity { get { return this.stadiumCapacity; } set { this.UpdateValue(ref this.stadiumCapacity, value); } } public string Country { get { return this.country; } set { this.UpdateValue(ref this.country, value); } } public bool IsChampion { get { return this.isChampion; } set { this.UpdateValue(ref this.isChampion, value); } } public List Countries => new List { "England", "Spain", "France", "Bulgaria" }; public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } protected void UpdateValue(ref T field, T newValue, [CallerMemberName] string propertyName = null) { if (!object.Equals(field, newValue)) { field = newValue; this.OnPropertyChanged(propertyName); } } }

的DataGrid/ columns文件夹中可以找到带有DataGrid列的示例浏览器应用程序

另请参阅

在本文中
Baidu
map