Я программно выбираюItem в datagrid. Проблема в том, что мне нужно вручную прокрутить вниз до selectItem. Мне нужно сделать это автоматически. до сих пор я пытался много, что и ничего не работает для меня ...wpf datagrid focus on the selectemItem
DataGrid:
<DataGrid x:Name="coreServiceLogDataGrid"
ItemsSource="{Binding}"
IsReadOnly="True"
RowDetailsVisibilityMode="VisibleWhenSelected"
SelectionMode="Single"
IsSynchronizedWithCurrentItem="True"
SelectedItem="{Binding Path=CurrentCoreServiceLogDataItem,Source={StaticResource synchronizer}, Mode=TwoWay}"
GotFocus="coreServiceLogDataGrid_GotFocus_1"
Style="{DynamicResource ResourceKey=dataGridStyle}"
...>
...
</DataGrid>
и код позади для GotFocus
:
private void coreServiceLogDataGrid_GotFocus_1(object sender, System.Windows.RoutedEventArgs e) {
if (coreServiceLogDataGrid.SelectedItem != null) {
coreServiceLogDataGrid.ScrollIntoView(coreServiceLogDataGrid.SelectedItem);
}
}
Вы подтвердили, что событие 'GotFocus' на самом деле пожары и' coreServiceLogDataGrid.SelectedItem' не равно нулю? – AbZy
@AbZy У меня есть обновленный код, но он по-прежнему не работает для меня. – RayOldProf