【发布时间】:2019-06-29 21:17:11
【问题描述】:
我想禁止选择DataGrid,因此我将属性IsHitTestVisible 设置为false,但随后它也会禁用ScrollBar。
如何通过仍然禁用DataGrid 上的选择来启用滚动条?
我能做的一件事是:
我可以更改DataGrid 上的选择颜色。问题是当我说 Trigger Property="DataGridRow.IsSelected" 它不起作用。另一方面,如果我说TriggerProperty="DataGridCell.IsSelected" 就像这里说的Row Selection in DataGrid 一样,它只会选择第一列而不是整行。此外,如果我说背景的值是透明的,它不会在单元格中显示文本。请帮忙。
<DataGrid x:Name="DGRunInfoItems" IsHitTesVisible="False" IsReadOnly="True" ColumnWidth="*" FontSize="{StaticResource BRControlNormalFontSize}" ScrollViewer.VerticalScrollBarVisibility="Auto" HeadersVisibility="None" CanUserAddRows="False" ItemsSource="{Binding RunViewModel.RunInfoDataTable}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Header}">
<DataGridTextColumn.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<Trigger Property="DataGridCell.IsSelected" Value="True">
<Setter Property="Background" Value="Transparent"/>
</Trigger>
</Style.Triggers>
<Style.Setters>
<Setter Property="FontWeight" Value="Bold"/>
</Style.Setters>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding Value}"/>
</DataGrid.Columns>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="MinHeight" Value="28"/>
</Style>
</DataGrid.RowStyle>
</DataGrid>
【问题讨论】: