I figured out how to highlight the row of interest. I can get the index of the column I am interested in and use ScrollIntoView in order to jump to it. However, it doesn t immediately pop out to the user. I d like to highlight the column, or change the ColumnHeaderStyle. I can t seem to figure out how to do it in the xaml or code behind.
另一种选择是,不强调整个行和一栏标题,而只是利益单位。 我这样做了,但可以得出数字。
我目前的数据来源就是:
<DataGrid x:Name="dtGridReads" AutoGenerateColumns="False"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode ="Standard"
EnableColumnVirtualization="True"
EnableRowVirtualization="True"
ScrollViewer.IsDeferredScrollingEnabled="True"
CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="True"
ItemsSource ="{Binding}" Block.TextAlignment="Center"
AlternatingRowBackground="#F1F1F1" RowBackground="White"
CanUserAddRows="False" CanUserDeleteRows="False" FrozenColumnCount="1"
GridLinesVisibility="None" ScrollViewer.ScrollChanged="dtGridReads_ScrollChanged">
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<Trigger Property="DataGridCell.IsSelected" Value="True">
<Setter Property="Background" Value="red" />
<Setter Property="BorderThickness" Value="0" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
我的守则如下:
public void ShowSelectedCell(int row, int column)
{
//dtGridReads.SelectedItem = dtGridReads.Items[row];
//dtGridReads.SelectedItem = dtGridReads.Columns[column];
//dtGridReads.CurrentColumn = dtGridReads.Columns[column];
dtGridReads.ScrollIntoView(dtGridReads.Items[row], dtGridReads.Columns[column]);
}
感谢。