【发布时间】:2013-02-21 19:16:32
【问题描述】:
我以编程方式在数据网格中选择项目。 问题是我必须手动向下滚动到 selectItem。我需要自动执行此操作。 到目前为止,我已经尝试了很多东西,但对我没有任何作用......
数据网格:
<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 我已经更新了代码,但它仍然对我不起作用。