dataGrid第一列为模板列,模板列里放checkbox的问题
描述:header里有一个控制全选/全不选的checkbox,每一行第一列也是一个checkbox(可以单选一行),现在是界面上有一个按钮,当点击这个按钮的时候,DataGrid的所有checkbox都是不可编辑的,
在后台按钮点击事件的里,我这样写dataGrid1.IsReadOnly=true,没有起作用,每一行的checkbox仍然可以点击,请问该怎么办,或者其他方法来实现这个效果.
xaml代码是这样子的:
<DataGrid Grid.Row="1" AutoGenerateColumns="False" Name="dataGrid1" DataContext="{Binding}" ItemsSource="{Binding}" CanUserAddRows="False" AlternationCount="2" ColumnHeaderStyle="{StaticResource CenterDataGridColumnHeaderStyle}" HorizontalGridLinesBrush="#FFF0F0F0" VerticalGridLinesBrush="#FFF0F0F0" Grid.ColumnSpan="2" CanUserSortColumns="False" CanUserResizeRows="False" > <DataGrid.Background> <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5"> <GradientStop Color="#FFFFFFFC" Offset="0" /> <GradientStop Color="#FFD0D0D0" Offset="1" /> </LinearGradientBrush> </DataGrid.Background> <DataGrid.Columns> <DataGridTemplateColumn Header="Replace?" IsReadOnly="False" MaxWidth="110" MinWidth="110"> <DataGridTemplateColumn.HeaderTemplate> <DataTemplate> <CheckBox Checked="ckbSelectedAll_Checked" Margin="0,0" Name="ckbSelectedAll" Unchecked="ckbSelectedAll_Unchecked">Replace?</CheckBox> </DataTemplate> </DataGridTemplateColumn.HeaderTemplate> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <CheckBox HorizontalAlignment="Center" IsChecked="{Binding Path=IsReplace, Mode=TwoWay}" VerticalAlignment="Center" Name="checkbox1" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked"/> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> <DataGridTextColumn Header="FileName" Width="Auto" Binding="{Binding Path=fileName}" MinWidth="100" IsReadOnly="True"/> <DataGridTextColumn Width="*" Binding="{Binding Path=fullName}" Header="Path" MinWidth="320" IsReadOnly="True"/> <DataGridTemplateColumn MinWidth="50" Width="Auto" Header="%" IsReadOnly="True"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <uc1:ucProgress x:Name="Progress"></uc1:ucProgress> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> <DataGridTextColumn Width="Auto" Binding="{Binding Path=sizeString}" Header="Size" MinWidth="80" CellStyle="{StaticResource RightCellStyle}" IsReadOnly="True"/> </DataGrid.Columns> <DataGrid.AlternatingRowBackground> <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5"> <GradientStop Color="#FFF0F0F0" Offset="0" /> <GradientStop Color="#FFD0D0D0" Offset="1" /> </LinearGradientBrush> </DataGrid.AlternatingRowBackground> </DataGrid>