title: ListBox scrolling does not work
body: <p>ListBoxEx is derived from ListBox. </p>
  
  <p>its default style is</p>
  
  <pre><code>&lt;ResourceDictionary
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="clr-namespace:ControlsLibrary"&gt;
      &lt;Style TargetType="{x:Type local:ListBoxEx}"&gt;
          &lt;Setter Property="SelectAllToggleStyle"&gt;
              &lt;Setter.Value&gt;
                  &lt;Style TargetType="ToggleButton"&gt;
                      &lt;Setter Property="Content" Value="Select All"/&gt;
                      &lt;Setter Property="Focusable" Value="True"/&gt;
                      &lt;Setter Property="Margin" Value="2,0,0,0"/&gt;
                      &lt;Setter Property="IsThreeState" Value="False"/&gt;
                  &lt;/Style&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
          &lt;Setter Property="Template"&gt;
              &lt;Setter.Value&gt;
                  &lt;ControlTemplate TargetType="{x:Type local:ListBoxEx}"&gt;
                      &lt;Border Background="{TemplateBinding Background}"
                              BorderBrush="{TemplateBinding BorderBrush}"
                              BorderThickness="{TemplateBinding BorderThickness}"
                              SnapsToDevicePixels="true"
                              Padding="{TemplateBinding Padding}"
                              VerticalAlignment="{TemplateBinding VerticalAlignment}"
                              HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                              Height="{TemplateBinding Height}"
                              Width="{TemplateBinding Width}"&gt;
                          &lt;DockPanel VerticalAlignment="Top" HorizontalAlignment="Stretch" LastChildFill="True"&gt;
                              &lt;CheckBox Name="PART_SelectAllToggle" DockPanel.Dock="Top"/&gt;
                              &lt;Separator Margin="4" Visibility="{Binding Path=Visibility, ElementName=PART_SelectAllToggle}" DockPanel.Dock="Top"/&gt;
                              &lt;ItemsPresenter DockPanel.Dock="Top"/&gt;
                          &lt;/DockPanel&gt;
                      &lt;/Border&gt;
                  &lt;/ControlTemplate&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
          &lt;Setter Property="ItemContainerStyle"&gt;
              &lt;Setter.Value&gt;
                  &lt;Style&gt;
                      &lt;Setter Property="ListBoxItem.Template"&gt;
                          &lt;Setter.Value&gt;
                              &lt;ControlTemplate TargetType="{x:Type ListBoxItem}"&gt;
                                  &lt;Border
                                  SnapsToDevicePixels="true" 
                                  Background="{TemplateBinding Background}" 
                                  BorderBrush="{TemplateBinding BorderBrush}" 
                                  BorderThickness="{TemplateBinding BorderThickness}"
                                  Padding="{TemplateBinding Padding}"
                                  VerticalAlignment="{TemplateBinding VerticalAlignment}"
                                  HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                                  Height="{TemplateBinding Height}"
                                  Width="{TemplateBinding Width}"&gt;
  
                                      &lt;ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
                                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/&gt;
  
                                  &lt;/Border&gt;
                                  &lt;ControlTemplate.Triggers&gt;
                                      &lt;Trigger Property="IsMouseOver" Value="True"&gt;
                                          &lt;Setter Property="Background" Value="{x:Static SystemColors.HighlightBrush}"/&gt;
                                      &lt;/Trigger&gt;
                                      &lt;Trigger Property="IsSelected" Value="True"&gt;
                                          &lt;Setter Property="Background" Value="{x:Static SystemColors.HotTrackBrush}"/&gt;
                                          &lt;Setter Property="Foreground" Value="White"/&gt;
                                      &lt;/Trigger&gt;
                                  &lt;/ControlTemplate.Triggers&gt;
                              &lt;/ControlTemplate&gt;
                          &lt;/Setter.Value&gt;
                      &lt;/Setter&gt;
                      &lt;Setter Property="Control.VerticalAlignment" Value="Center"/&gt;
                      &lt;Setter Property="Control.FocusVisualStyle"&gt;
                          &lt;Setter.Value&gt;
                              &lt;Style TargetType="Control"&gt;
                                  &lt;Setter Property="Template"&gt;
                                      &lt;Setter.Value&gt;
                                          &lt;ControlTemplate&gt;
                                              &lt;Rectangle Margin="0" StrokeThickness="2"  Stroke="Black" SnapsToDevicePixels="true"/&gt;
                                          &lt;/ControlTemplate&gt;
                                      &lt;/Setter.Value&gt;
                                  &lt;/Setter&gt;
                              &lt;/Style&gt;
                          &lt;/Setter.Value&gt;
                      &lt;/Setter&gt;
                  &lt;/Style&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
          &lt;Setter Property="Padding" Value="4"/&gt;
      &lt;/Style&gt;
  &lt;/ResourceDictionary&gt;
  </code></pre>
  
  <p>No stack panels.</p>
  
  <p>the xaml of the test window is:</p>
  
  <pre><code>&lt;Window x:Class="WpfTesting.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:cl="clr-namespace:ControlsLibrary;assembly=ControlsLibrary" xmlns:System="clr-namespace:System;assembly=mscorlib" Title="MainWindow" Height="350" Width="300"&gt;
      &lt;DockPanel Margin="5" HorizontalAlignment="Stretch" VerticalAlignment="Top"&gt;
          &lt;cl:ListBoxEx  BorderThickness="2" BorderBrush="Black" ShowSelectAllToggle="True" Height="100" DockPanel.Dock="Top"&gt;
              &lt;cl:ListBoxEx.Items&gt;
                  &lt;System:String&gt;QWERTY1&lt;/System:String&gt;
                  &lt;System:String&gt;QWERTY2&lt;/System:String&gt;
                  &lt;System:String&gt;QWERTY3&lt;/System:String&gt;
                  &lt;System:String&gt;QWERTY4&lt;/System:String&gt;
                  &lt;System:String&gt;QWERTY5&lt;/System:String&gt;
                  &lt;System:String&gt;QWERTY6&lt;/System:String&gt;
                  &lt;System:String&gt;QWERTY7&lt;/System:String&gt;
                  &lt;System:String&gt;QWERTY8&lt;/System:String&gt;
              &lt;/cl:ListBoxEx.Items&gt;
          &lt;/cl:ListBoxEx&gt;
      &lt;/DockPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>I can not understand why scrolling does not work. =(
  Probably I'm missing something with the layout...but what?</p>