在wpf数据网格中,如果数据网格宽于列宽的总和,则会得到尾随空格。默认情况下,单击此区域不会选择行,也不会突出显示选择行覆盖此区域。
如何从此区域注册点击以选择适当的行,并允许选择行突出显示扩展到此区域。
这个问题: WPF DataGrid full row selection 类似但我不能添加虚拟列,也不能将列宽设置为*。
答案 0 :(得分:2)
<DataGrid Name="dg">
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<EventSetter Event="MouseLeftButtonDown" Handler="DataGridRow_MouseLeftButtonDown" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{StaticResource {x:Static SystemColors.HighlightBrushKey}}" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
</DataGrid>
这个代码隐藏在
之后private void DataGridRow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
dg.SelectedIndex = (sender as DataGridRow).GetIndex();
}
应该有用。