修改C1DataGrid for Silverlight中CheckBox列的显示外观

发布时间:2012/11/16 00:11 发布者:葡萄城产品团队

返回博客中心

在C1DataGrid for Silverlight中,如果包含DataGridCheckBoxColumn类型的列,你会发现该列中单元格处于非编辑状态时,CheckBox都被显示成灰色。



本文也将主要介绍如何改变CheckBox列处于非编辑状态时的显示样式,基本思路是在LoadedCellPresenter事件中将C1.Silverlight.DataGrid.ReadOnlyCheckBox替换为正常的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;
        }
    }
复制代码

运行截图:


源码下载:VS2010 + ComponentOne Studio for Silverlight 2012V2
C#:

DataGrid_StylingCheckBox_C.zip (32.38 K, 下载次数:67)


VB.NET:

DataGrid_StylingCheckBox_VB.zip (32.43 K, 下载次数:34)

关于葡萄城

赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。

了解详情,请访问葡萄城官网