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