0
我以编程方式在数据网格中选择项目。 问题是,虽然我不得不手动向下滚动selectItem。我需要自动执行此操作。 到目前为止,我已经尝试了许多的事情,没有什么工作对我来说...wpf datagrid专注于选择项目
的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'不为null? – AbZy 2013-02-21 19:26:23
@AbZy我有更新的代码,但它仍然不适合我。 – RayOldProf 2013-02-21 19:31:47