Datagrid scroll bar stops working

心不动则不痛 提交于 2019-12-13 16:32:34

问题


When I run the app, the vertical scroll bar works as expected. However, when I add a new line/row, the bar (control that should go up and down on the slider) doesn't slide. With the mouse wheel I can scroll up and down the list of rows, and I can click on the up and down arrows. So the scroll bar works, but not as expected. The control should slide up and down, like it does at first, but after adding that new line, it does not.

I hope that is clear enough, I've searched many issues to find this peculiar behavior, but was unsuccessful. Here is the XAML, in part, as it is now:

<DataGrid x:Name="inventoryDataGrid" AutoGenerateColumns="False" 
  SelectedValuePath="Id"
  EnableRowVirtualization="True"               
  EnableColumnVirtualization="True" 
  Style="{DynamicResource DataGridDemoStyle}"
  CanUserSortColumns="True"
  VerticalAlignment="Top" 
  ItemsSource="{Binding Source={StaticResource claimInventoryViewSource}}" 
  RowEditEnding="dgInv_RowEditEnding"  
  CellEditEnding="dgInv_CellEditEnding"
  SelectionChanged="dgInv_SelectionChanged"                                             
  IsSynchronizedWithCurrentItem="True"  CanUserAddRows="False" 
  RowHeaderWidth="0"
  Sorting="DataGrid_Standard_Sorting" MouseDoubleClick="inventoryDataGrid_DoubleClick"
  CanUserDeleteRows="True"
  SelectionMode="Single"
  HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Visible"
  Width="999.5"
  CommandManager.PreviewCanExecute="Grid_PreviewCanExecute" Grid.Column="0"
  Grid.Row="1"   
  Margin="0,3,0,0" RowDetailsVisibilityMode="VisibleWhenSelected" Height="227"     
  LostFocus="inventoryDataGrid_LostFocus" Background="#FFFCF2E7"   
  AlternatingRowBackground="#FFF2F2D6" RowBackground="#FF6FC4BF"
  GotFocus="inventoryDataGrid_GotFocus">
<DataGrid.Resources>
 <Style x:Key="DataGridCellStyle" TargetType="{x:Type DataGridCell}" >
  <Style.Triggers>
   <Trigger Property="IsSelected" Value="True">
    <Setter Property="Foreground" Value="White"/>
   </Trigger>
  </Style.Triggers>
 </Style>
</DataGrid.Resources>
<DataGrid.Columns>

Thanks!


回答1:


I was able to solve this issue. The problem was that there was code I implemented a long time ago, in an EndEdit routine (found here: EndEdit equivalent in WPF), which somehow caused this erratic behavior in my datagrid scrollbar.

Once I removed this code, my scrollbar worked without problems. Then of course I had to research a way to save the data in text boxes without the use of EndEdit, but that is way off topic for this Question.



来源:https://stackoverflow.com/questions/8107618/datagrid-scroll-bar-stops-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!