【发布时间】:2014-09-30 06:48:21
【问题描述】:
以下是我的数据网格的定义:
<DataGrid
Name="ODataGrid"
AutoGenerateColumns="False"
Grid.Row="0"
Grid.Column="0"
CanUserAddRows="False"
AlternationCount="2"
HeadersVisibility="All"
IsReadOnly="True"
SelectionUnit="FullRow"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="#EBF0F0"
AlternatingRowBackground="#E9E8EF"
HorizontalGridLinesBrush="#7F7F7F"
VerticalGridLinesBrush="#7F7F7F"
SelectedItem="{Binding vmItem}"
CellStyle="{StaticResource ODataGridCellStyle}"
ItemsSource="{Binding vmResults}"
Tag="{Binding DataContext, ElementName=BaseGrid}">
以下是我为得到错误而采取的步骤。
- 默认选择第一行。
- 我在数据网格中选择了另一行。
- 我通过单击其中一个列标题进行排序。
- 我通过拖动垂直滚动条进行滚动。
- 最初的第一行不知何故是自动选择的。
- 所以现在有 2 行被选中。
为什么会有这种行为?无论如何要防止滚动时自动选择?谢谢。
【问题讨论】:
-
您是否检查过 DataGrid 没有设置 SelectionMode 属性 Set dg.SelectionMode = DataGridSelectionMode.Extended 将选择多于一行?
-
嗨,我的 SelectionMode 必须是扩展的,因此我无法将其设置为 Single,尽管这样可以解决问题。
标签: wpf datagrid wpfdatagrid