【发布时间】:2011-01-25 10:55:32
【问题描述】:
我希望创建一个滚动查看器,它显示其垂直滚动条,无论它是否有要向下滚动的项目。通过这样做,我试图在用户滚动到底部时从数据库中动态获取更多数据。数据存储在数据网格 (dgGrid) 中,并由滚动查看器 (svMain) 包装(见下文)。使用触发 ScrollViewer.ScrollChanged 事件的方法检索数据库中的数据。
<ScrollViewer Grid.Row="0" VerticalScrollBarVisibility="Visible" DockPanel.Dock="Top" Name="svMain" cal:Message.Attach="[Event ScrollChanged] = [Action ScrollMaster($eventArgs)]">
<StackPanel>
<Grid Visibility="{Binding Path=IsFormView, Converter={StaticResource booleanToVisibilityConverter}}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="200"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal">
<CheckBox IsChecked="{Binding MasterDTO.ActiveFlag, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<Label Content="Active"/>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="0">
<con:MandatoryLabel Text="Country Id" />
<TextBox Text="{Binding MasterDTO.CountryId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1">
<con:MandatoryLabel Text="Currency"/>
<TextBox Text="{Binding MasterDTO.Currency, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</StackPanel>
</Grid>
<!-- Grid View -->
<DockPanel Visibility="{Binding Path=IsGridView, Converter={StaticResource booleanToVisibilityConverter}}">
<DataGrid Name="dgGrid" Style="{StaticResource ReadOnlyDatagrid}" SelectedItem="{Binding Path=MasterDTO, Mode=TwoWay}" ItemsSource="{Binding MasterDTOs, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" cal:Message.Attach="[Event SelectionChanged] = [Action GridSelect]">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Active">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<controls:YesNoLabel Value="{Binding ActiveFlag}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Country Id" Binding="{Binding CountryId}"/>
<DataGridTextColumn Header="Currency" Binding="{Binding Currency}"/>
</DataGrid.Columns>
</DataGrid>
</DockPanel>
</StackPanel>
</ScrollViewer>
问题是即使我将滚动查看器的 VerticalScrollBarVisibility 属性设置为可见(并且始终显示垂直滚动条),滚动条被禁用,并且只要数据网格中的数据量很大,就没有滚动拇指可见适合屏幕的高度。如果我将屏幕大小调整为更小的尺寸,则启用垂直滚动条并且我可以移动拇指。但是,无论视口的内容是否可以容纳其内容,我都希望启用滚动条及其拇指。有人可以提供帮助吗?
谢谢!
【问题讨论】:
标签: wpf xaml scrollviewer