WPF DataGrid-禁用DataGridCheckBoxColumn
我正在尝试使用datagridView创建多重检查网格 我已经扩展了网格,除了在DataGridCheckBoxColumn中选中复选框时,它会选择行之外,其他一切都可以正常工作。因为当所选行发生更改时,有大量的加载正在进行,这使得快速选择复选框的速度变慢。当我在复选框列中选择复选框时,是否有方法或建议防止选中该行? 我已经用这个方法处理了gridView的其他行(当我点击它们时,它们被禁用了)。现在的问题是DataGridCheckBoxColumn PS:我正在使用DataGridCheckBoxColumn而不是CheckBox搜索解决方案 我需要的就是在DataGridCheckBoxColumn中使用这个WPF DataGrid-禁用DataGridCheckBoxColumn,wpf,xaml,Wpf,Xaml,我正在尝试使用datagridView创建多重检查网格 我已经扩展了网格,除了在DataGridCheckBoxColumn中选中复选框时,它会选择行之外,其他一切都可以正常工作。因为当所选行发生更改时,有大量的加载正在进行,这使得快速选择复选框的速度变慢。当我在复选框列中选择复选框时,是否有方法或建议防止选中该行? 我已经用这个方法处理了gridView的其他行(当我点击它们时,它们被禁用了)。现在的问题是DataGridCheckBoxColumn PS:我正在使用DataGridCheck
CellStyle=“{StaticResource DisableSelection}”
我怎样才能让它工作呢
<DataGrid ItemsSource="{Binding GridModel}" x:Name="patientGrid" VerticalAlignment="Top" AutoGenerateColumns="False" CanUserAddRows="false" Height="484" Grid.RowSpan="2" RenderTransformOrigin="0.497,0.551" >
<DataGrid.Resources>
<Style x:Key="DisableSelection" TargetType="DataGridCell">
<Setter Property="Focusable" Value="False"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="BorderBrush" Value="Transparent"/>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridCheckBoxColumn Header="Choose" x:Name="choose" >
<DataGridCheckBoxColumn.CellStyle>
<Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
<EventSetter Event="CheckBox.Checked" Handler="OnChecked"/>
<EventSetter Event="CheckBox.Unchecked" Handler="OnChecked"/>
<Setter Property="Background" Value="Transparent" />
</Style>
</DataGridCheckBoxColumn.CellStyle>
</DataGridCheckBoxColumn>
<DataGridTextColumn CellStyle="{StaticResource DisableSelection}" Header="nmbr" x:Name="workIdcl" Binding="{Binding ID}" IsReadOnly="True" />
谢谢。使用
DataGridCheckBoxColumn
,在选中复选框之前,实际选中了单元格
您可以用DataGridTemplateColumn
替换DataGridCheckBoxColumn
,并处理复选框的PreviewMouseLeftButtonDown
事件:
private void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
CheckBox checkBox = (CheckBox)sender;
checkBox.IsChecked = !checkBox.IsChecked.HasValue || !checkBox.IsChecked.Value;
}
XAML:
<DataGridTemplateColumn Header="Choose" x:Name="choose">
<DataGridTemplateColumn.CellStyle>
<Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
<Setter Property="Background" Value="Transparent" />
</Style>
</DataGridTemplateColumn.CellStyle>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox PreviewMouseLeftButtonDown="OnPreviewMouseLeftButtonDown"
Checked="OnChecked"
Unchecked="OnUnchecked"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
很抱歉,我需要使用DataGridCheckBoxColumn而不是CheckBox@abdou_dev:为什么?那么您就不能自定义复选框了。当然,除非您创建自定义的DataGridCheckBoxColumn
。为什么需要一个DataGridCheckBoxColumn
?