我该如何禁用 WPF Toolkit 的 DataGrid
中的选择功能?
我尝试修改适用于 ListView
的解决方案(来自 WPF ListView turn off selection),但那并不起作用:
<tk:DataGrid>
<tk:DataGrid.ItemContainerStyle>
<Style TargetType="{x:Type tk:DataGridRow}">
<Setter Property="Focusable" Value="false"/>
</Style>
</tk:DataGrid.ItemContainerStyle>
<tk:DataGrid.CellStyle>
<Style TargetType="{x:Type tk:DataGridCell}">
<Setter Property="Focusable" Value="false"/>
</Style>
</tk:DataGrid.CellStyle>
</tk:DataGrid>
<Setter Property="Foreground" Value="Black"/>
,否则选择的文本将默认为白色。请注意保持原意,尽可能让翻译更加通俗易懂,不提供解释或其他额外信息。 - JiBéDoublevé<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource Self}, Path=Foreground}"/>
,这会将其设置为它已经存在的值。奇怪的是,在列定义上明确设置颜色也会移除颜色更改,而不需要setter。 - XcelledBasedOn = "{StaticResource {x:Type DataGridCell}}"
和BasedOn = "{StaticResource {x:Type DataGridRow}}"
...结果只会删除边框,而不是整个默认样式。 - Beauty