我有一个动态构建的stackpanel,填充了一定数量的用户控件。由于空间有限,我在堆栈面板上使用Scrollviewer,带有样式的滚动条。
接下来发生的事情相当令人讨厌,当我一直滚动时,在最后一个控件和scrollviewer / stackpanel底部之间总会有一点额外的缓冲区。我认为发生这种情况的原因是滚动查看区域设置为特定高度(我需要保留)。用户控件的大小由该高度除以用户控件的数量(例如10)确定。当我向下滚动并且显示较少的用户控件(假设为8)时,它会用背景颜色填充预定高度的其余部分。
请告知我该如何更改滚动条或滚动查看器控件的行为,以便额外部分消失?
滚动查看器的代码
<Border Name="ScrollViewerBorder" BorderThickness="1,0,1,0" BorderBrush="{StaticResource BorderLight}" Height="{Binding MidHeight}" >
<ScrollViewer Name="midScroll1" Style="{StaticResource ScrollViewer04}" d:DesignHeight="612" Width="Auto" VerticalScrollBarVisibility="Hidden" CanContentScroll="False" Background="{StaticResource LtBlue}" >
<StackPanel DockPanel.Dock="left" Name="Midmenu" Background="{StaticResource LtBlue}" Width="300" CanVerticallyScroll="True">
</StackPanel>
</ScrollViewer>
</Border>
滚动条样式部分xaml
<ControlTemplate x:Key="VerticalScrollBar04" TargetType="{x:Type ScrollBar}" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="56" />
<RowDefinition Height="0.00001*" />
<RowDefinition Height="56" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>
<!--Border around buttons and thumb-->
<Border Grid.RowSpan="3" CornerRadius="0" Background="{StaticResource White}" BorderBrush="{StaticResource ButtonLine}" BorderThickness="1" />
<RepeatButton Grid.Row="0" Height="56" Command="ScrollBar.LineUpCommand" Style="{StaticResource ScrollBarTopButton04}" />
<Track Name="PART_Track" Grid.Row="1" IsDirectionReversed="true" ViewportSize="NaN" >
<Track.DecreaseRepeatButton>
<RepeatButton Command="ScrollBar.PageUpCommand" Style="{StaticResource ScrollBarPageButton04}" />
</Track.DecreaseRepeatButton>
<Track.Thumb>
<Thumb Style="{StaticResource ScrollBarThumb04}" Margin="0,10,0,10" />
</Track.Thumb>
<Track.IncreaseRepeatButton>
<RepeatButton Command="ScrollBar.PageDownCommand" Style="{StaticResource ScrollBarPageButton04}" />
</Track.IncreaseRepeatButton>
</Track>
<RepeatButton Grid.Row="2" Height="56" Command="ScrollBar.LineDownCommand" Style="{StaticResource ScrollBarBottomButton04}" />
</Grid>
</ControlTemplate>