Xamarin的Telerik UI?下载30天免费试用

CellTap命令

DataGrid CellTap命令在网格单元格(即数据行和列的交集)上处理Tap手势。

例子

下面是RadDataGrid CellTap命令的工作示例:

首先,创建所需的业务对象,例如具有以下属性的Country类型:

公共类国家{公共国家(字符串名称,双人口){this。Name = Name;这一点。Population =人口;}公共字符串名称{获取;设置;}公共double人口{得到;设置;}}

下面是用作绑定上下文的简单数据:

var source = new ObservableCollection<国家>();源。Add(新国家(“莫桑比克”,24692000));源。Add(新国家(“巴拉圭”,6725000));源。Add(新国家(“土库曼斯坦”,5663000));源。Add(新国家(“蒙古”,3027000));源。Add(new Country("Japan", 127000000)); source.Add(new Country("Bulgaria", 7128000)); source.Add(new Country("Chad", 14450000)); source.Add(new Country("Netherlands", 17020000)); this.BindingContext = source;

然后将CellTap操作作为命令处理。首先,创建一个继承于DataGridCommand的类,并相应地设置它的Id属性。你还需要重写CanExecute和Execute方法,如下面的例子所示:

公共类CellTapUserCommand: DataGridCommand {public CellTapUserCommand() {Id = datagridcommanddid . celltap;} public override bool CanExecute(对象参数){返回true;} public override void执行(对象参数){var context = parameter as DataGridCellInfo;var cellTap = $"你点击{context. var cellTap = $"Value}在{context.Column内。column \n";Application.Current.MainPage。DisplayAlert("CellTap Command: ", CellTap, "OK");this.Owner.CommandService.ExecuteDefaultCommand (DataGridCommandId。CellTap、参数);}}

然后将此命令添加到RadDataGrid实例的Commands集合中:

grid.Commands。添加(新CellTapUserCommand ());

在XAML中定义RadDataGrid:

浏览器应用程序包含一个演示如何使用CellTap命令的示例。Commands示例位于DataGrid/Commands文件夹中。

另请参阅

在本文中
Baidu
map