title: Adjusting the scale of the ScrollViewer scroolbar
body: <p>I have a stackpanel being built dynamically, filling with a certain amount of user controls. Because the space is limited, I use Scrollviewer on the stack panel, with a styled Scrollbar.</p>
  
  <p>What happens next is fairly annoying, As I scroll all the way there is always a little extra buffer between the last control and the bottom of the scrollviewer/stackpanel. I think the reason this happens is that the scrollviewing area is set to a specific height(which I need to keep). The size of the user controls is determined by that height divided by number of user controls (for example 10). What happens is when I scroll all the way down and there are less user controls to show (lets say 8) it fills out the rest of the predetermined height with background color. </p>
  
  <p>Please, advise on what can I do to change the behavior of scroll bar, or scrollviewer control, so the extra part disappears?</p>
  
  <p>Code for the scrollviewer</p>
  
  <pre><code>        &lt;Border Name="ScrollViewerBorder" BorderThickness="1,0,1,0" BorderBrush="{StaticResource BorderLight}" Height="{Binding MidHeight}" &gt;
              &lt;ScrollViewer Name="midScroll1" Style="{StaticResource ScrollViewer04}" d:DesignHeight="612" Width="Auto" VerticalScrollBarVisibility="Hidden" CanContentScroll="False" Background="{StaticResource LtBlue}" &gt;
  
                  &lt;StackPanel DockPanel.Dock="left" Name="Midmenu" Background="{StaticResource LtBlue}" Width="300" CanVerticallyScroll="True"&gt;
              &lt;/StackPanel&gt;
              &lt;/ScrollViewer&gt;
          &lt;/Border&gt;
  </code></pre>
  
  <p>part of the scroll bar style xaml</p>
  
  <pre><code>&lt;ControlTemplate x:Key="VerticalScrollBar04" TargetType="{x:Type ScrollBar}" &gt;
      &lt;Grid&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="56" /&gt;
              &lt;RowDefinition Height="0.00001*" /&gt;
              &lt;RowDefinition Height="56" /&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="50" /&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;!--Border around buttons and thumb--&gt;
          &lt;Border Grid.RowSpan="3" CornerRadius="0" Background="{StaticResource White}" BorderBrush="{StaticResource ButtonLine}" BorderThickness="1" /&gt;
  
          &lt;RepeatButton Grid.Row="0" Height="56" Command="ScrollBar.LineUpCommand" Style="{StaticResource ScrollBarTopButton04}" /&gt;
  
          &lt;Track Name="PART_Track" Grid.Row="1" IsDirectionReversed="true" ViewportSize="NaN" &gt;
              &lt;Track.DecreaseRepeatButton&gt;
                  &lt;RepeatButton Command="ScrollBar.PageUpCommand" Style="{StaticResource ScrollBarPageButton04}" /&gt;
              &lt;/Track.DecreaseRepeatButton&gt;
              &lt;Track.Thumb&gt;
                  &lt;Thumb Style="{StaticResource ScrollBarThumb04}" Margin="0,10,0,10" /&gt;
              &lt;/Track.Thumb&gt;
              &lt;Track.IncreaseRepeatButton&gt;
                  &lt;RepeatButton Command="ScrollBar.PageDownCommand" Style="{StaticResource ScrollBarPageButton04}" /&gt;
              &lt;/Track.IncreaseRepeatButton&gt;
          &lt;/Track&gt;
  
          &lt;RepeatButton Grid.Row="2" Height="56" Command="ScrollBar.LineDownCommand" Style="{StaticResource ScrollBarBottomButton04}" /&gt;
  
      &lt;/Grid&gt;
  &lt;/ControlTemplate&gt;
  </code></pre>