论坛首页 编程语言技术论坛

wpf 多选框 使用滚动条造成选中和取消选中

浏览 2812 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2013-02-04  
WPF
操作顺序:

1、手动选中 多选框,每列3个

2、滚动鼠标滚轮或下拉滚动条

3、返回查看之前选中的多选框。

问题的现象:

1、对于DataGridTemplateColumn 选中效果被丢失,剩余最后选中的行保持选中状态

2、对于DataGridCheckBoxColumn选中效果未丢失,滚动时有拖影效果

补充:

1、不使用DataGridCheckBoxColumn的原因是 DataGridCheckBoxColumn列需要单击2次才能选中

2、DataGridTemplateColumn 选中的行被隐藏会触发unchecked事件,造成选中的数据不被记录

3、如果考虑使用ScrollViewer如何保证列头不被看不到

对于DataGrid中以上2中checkbox的使用,不知是否有更优方案,希望得到各位高手的指点。

xaml代码:
<Grid Margin="0,0,45,17">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" ></RowDefinition>
        </Grid.RowDefinitions>
        <DataGrid Width="400" Height="400" AutoGenerateColumns="False" Name="dg" Grid.RowSpan="1" VerticalScrollBarVisibility="Auto" MouseWheel="dg_MouseWheel">
            <DataGrid.Columns>

                <DataGridCheckBoxColumn Binding="{Binding 1}" Width="auto" Header="DataGridCheckBoxColumn" >

                </DataGridCheckBoxColumn>

                <DataGridTemplateColumn Width="auto">
                    <DataGridTemplateColumn.HeaderTemplate>
                        <DataTemplate>
                            <TextBlock>DataGridTemplateColumn</TextBlock>
                        </DataTemplate>
                    </DataGridTemplateColumn.HeaderTemplate>

                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox IsChecked="{Binding 2}" Unchecked="CheckBox_Unchecked_1" Checked="CheckBox_Checked_1"></CheckBox>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>

    </Grid>



 public Window1()
        {
            InitializeComponent();
            DataTable dt = new DataTable();
            dt.Columns.Add("1", typeof(Boolean));
            dt.Columns.Add("2", typeof(Boolean));
            for (int i = 0; i < 200; i++)
            {
               DataRow dr= dt.NewRow();
               dr[0] = false;
               dr[1] = false;
               dt.Rows.Add(dr);
            }
            dg.ItemsSource = dt.DefaultView;
        }

   发表时间:2013-02-18  
http://social.msdn.microsoft.com/Forums/zh-CN/wpfzhchs/thread/4d16fa21-7a07-4564-a3ba-3ff651b09b73?prof=required
这个是满意答复
0 请登录后投票
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics