C1DataGrid for Silverlight 修改 CheckBox 列外观

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

本文也将主要介绍如何改变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
1.C# 2.VB.NET

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值