原标题:C1DataGrid for WPF使用技巧之改变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)
PS: 关于ComponentOne,这些产品你可以关注>>本文转载自葡萄城2015岁末扫尾之战!全球厂商携手放利!优惠详情点击查看>>
有用(0)没用(0)
本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:慧都控件网 [http://www.evget.com]
本文地址:http://www.evget.com/article/2015/12/29/23296.html返回搜狐,查看更多
责任编辑: