改变CheckBox列外观
在上一篇中,我们讲述了DataTime列的设计:C1DataGrid for WPF使用技巧五:绑定TimeSpan属性。本章就接着介绍有关CheckBox列。
在C1DataGrid中,如果包含一个DataGridCheckBoxColumn,你就会发现在Column的单元格中的CheckBox是灰色的,因此它不能编辑。
比如如下单元格是不可用的:
这种不可用的状态是设计,是因为内部的ReadOnlyCheckBox类。现在如果想要改变这种样式,变成可编辑的状态。
那么本文,就将不可编辑的checkbox列改变状态。
最基本的知识就是使用LoadedCellPresenter事件,然后设置一个CheckBox。
代码片段如下:
void c1DataGrid1_LoadedCellPresenter(object sender, C1.Silverlight.DataGrid.DataGridCellEventArgs e) { if (e.Cell.Column.GetType() == typeof(C1.Silverlight.DataGrid.DataGridCheckBoxColumn)) { CheckBox newCheckBox = new CheckBox(); System.Windows.Data.Binding bnd = new System.Windows.Data.Binding(); bnd.Source = e.Cell; bnd.Path = new PropertyPath("Value"); bnd.Mode = System.Windows.Data.BindingMode.TwoWay; newCheckBox.SetBinding(CheckBox.IsCheckedProperty, bnd); e.Cell.Presenter.Content = newCheckBox; e.Cell.Presenter.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; e.Cell.Presenter.VerticalContentAlignment = System.Windows.VerticalAlignment.Center; } }
因此改变后的样式,就会如下图所示:
本文的参考示例如下:
DataGrid_StylingCheckBox_C.zip (32.38 kb)
C1DataGrid的在线英文产品文档地址:
http://helpcentral.componentone.com/nethelp/C1datagridWPF/
如果你对C1DataGrid感兴趣,请到我们的官网下载最新版本:/download/?pid=6
如果你有疑问,可以到GCDN论坛获得技术支持:http://gcdn.grapecity.com.cn/showforum-138.html
《C1DataGrid for WPF使用技巧》系列文章: