title: ListBox control used to display collection of complex user controls doesn't horizontally scroll
body: <p>I've been fighting this issue with ListBox for a long time.  I have a MVVM application for displaying stock option chains.</p>
  
  <p>The OptionChainViewModel creates each individual chain - one for each of the available expiration periods.</p>
  
  <p>Then I attempt to display these "chains" with the ListBox which has an ItemsPanelTemplate into which I have a StackPanel.  </p>
  
  <p>Although I can get the HorizontalScrollBar to display, it is not active and I cannot get the content to scroll horizontally.  I've tried setting MaxWidth on the StackPanel as well as the ListBox itself to no avail.  I've also set MaxWidth and Width on the OptionViewModel objects to no avail.  </p>
  
  <p>I've viewed the visual tree, found the scrollviewer just prior to the ListBoxItems and it's MaxWidth and MaxHeight were set to "infinity" so I inserted a method on my viewmodel which is called when I click a button in the view.  The method finds the scrollviewer and sets the MaxWidth and MaxHeight values for the scrollviewer...but even that didn't cause the horizontal scroll bar to work.</p>
  
  <pre><code>                        &lt;ListBox Name="lbAllOptions"
                                   Width="600"
                                   MaxHeight="400"
                                   MaxWidth="500"
                                   IsSynchronizedWithCurrentItem="True"
                                   ScrollViewer.CanContentScroll="True"
                                   ScrollViewer.HorizontalScrollBarVisibility="Visible"
                                   ScrollViewer.VerticalScrollBarVisibility="Hidden"
                                   ItemsSource="{Binding AllChains}"&gt;
                              &lt;ListBox.ItemsPanel&gt;
                                  &lt;ItemsPanelTemplate&gt;
              &lt;StackPanel Orientation="Horizontal" /&gt;
              &lt;!-- &lt;pnls:CustomPanel  MaxWidth="500" MaxHeight="400"/&gt;--&gt;
              &lt;/ItemsPanelTemplate&gt;
                              &lt;/ListBox.ItemsPanel&gt;
                          &lt;/ListBox&gt;
  </code></pre>
  
  <p>The relevant code for each option chain item is:</p>
  
  <pre><code>&lt;DockPanel&gt;
      &lt;GroupBox MaxWidth="500"
                HorizontalAlignment="Left"&gt;
          &lt;GroupBox.HeaderTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;StackPanel x:Name="stack"
                              Orientation="Horizontal"&gt;
                      &lt;TextBlock Text="{Binding Source={x:Reference tblockDName}, Path=Text}"
                                 DataContext="{Binding DataContext, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type GroupBox}}}" /&gt;
                  &lt;/StackPanel&gt;
              &lt;/DataTemplate&gt;
          &lt;/GroupBox.HeaderTemplate&gt;
          &lt;Grid DockPanel.Dock="Bottom"
                Margin="0,2,4,2"&gt;
              &lt;StackPanel Grid.Row="0"
                          Grid.Column="1"
                          MaxHeight="300"
                          MaxWidth="400"
                          Orientation="Vertical"&gt;
                  &lt;TextBlock x:Name="tblockDName"
                             Text="{Binding Path=DisplayName}"
                             Visibility="Collapsed" /&gt;
                  &lt;Label Content="Calls"
                         HorizontalAlignment="Left"
                         Name="lblCallOptionChains"
                         VerticalAlignment="Top" /&gt;
                  &lt;DataGrid   MinHeight="200"
                              MinWidth="200"
                              MaxWidth="500"
  
                              HorizontalAlignment="Left"
                              AutoGenerateColumns="False"
                              EnableRowVirtualization="True"
                              AlternatingRowBackground="LightGray"
                              SelectionUnit="FullRow"
                              Name="dgridCallOptionChain"
                              IsSynchronizedWithCurrentItem="True"
                              ItemsSource="{Binding _CallOptionList}"
                              SelectedItem="{Binding Path=SelectedOption, Mode=TwoWay}"
                              VerticalAlignment="Stretch"
                              HorizontalScrollBarVisibility="Visible"
                              VerticalScrollBarVisibility="Visible"
                              MaxHeight="200"
                              IsManipulationEnabled="True"&gt;
                      &lt;i:Interaction.Triggers&gt;
                          &lt;i:EventTrigger EventName="PreviewKeyDown"&gt;
                              &lt;ei:CallMethodAction TargetObject="{Binding}"
                                                   MethodName="SampleKeyDownEventHandler" /&gt;
                          &lt;/i:EventTrigger&gt;
                          &lt;i:EventTrigger EventName="PreviewTextInput"&gt;
                              &lt;ei:CallMethodAction TargetObject="{Binding}"
                                                   MethodName="SampleTextInputEventHandler" /&gt;
                          &lt;/i:EventTrigger&gt;
                      &lt;/i:Interaction.Triggers&gt;
                      &lt;DataGrid.Columns&gt;
                          &lt;DataGridTextColumn Header="Symbol"
                                              Binding="{Binding OCSymbol}" /&gt;
                          &lt;DataGridTextColumn Header="Strike"
                                              Binding="{Binding OCStrike}" /&gt;
                          &lt;DataGridTextColumn  Header="Mid"
                                               Binding="{Binding OCMid}" /&gt;
                          &lt;DataGridTextColumn Header="Interest"
                                              Binding="{Binding OCInterest}" /&gt;
                          &lt;DataGridTextColumn Header="Model"
                                              Binding="{Binding OCModel}" /&gt;
                          &lt;DataGridTextColumn Header="Position"
                                              Binding="{Binding OCPosition}" /&gt;
                      &lt;/DataGrid.Columns&gt;
                  &lt;/DataGrid&gt;
                  &lt;Label Content="Puts"
                         HorizontalAlignment="Left"
                         Name="lblPutOptionChains"
                         VerticalAlignment="Top" /&gt;
                  &lt;DataGrid   MinHeight="200"
                              MinWidth="200"
                              MaxWidth="500"
  
                              HorizontalAlignment="Left"
                              AutoGenerateColumns="False"
                              EnableRowVirtualization="True"
                              AlternatingRowBackground="LightGray"
                              SelectionUnit="FullRow"
                              Name="dgridPutOptionChain"
                              IsSynchronizedWithCurrentItem="True"
                              ItemsSource="{Binding _PutOptionList}"
                              SelectedItem="{Binding Path=SelectedOption, Mode=TwoWay}"
                              VerticalAlignment="Stretch"
                              HorizontalScrollBarVisibility="Visible"
                              VerticalScrollBarVisibility="Visible"
                              MaxHeight="200"
                              IsManipulationEnabled="True"&gt;
                      &lt;i:Interaction.Triggers&gt;
                          &lt;i:EventTrigger EventName="PreviewKeyDown"&gt;
                              &lt;ei:CallMethodAction TargetObject="{Binding}"
                                                   MethodName="SampleKeyDownEventHandler" /&gt;
                          &lt;/i:EventTrigger&gt;
                          &lt;i:EventTrigger EventName="PreviewTextInput"&gt;
                              &lt;ei:CallMethodAction TargetObject="{Binding}"
                                                   MethodName="SampleTextInputEventHandler" /&gt;
                          &lt;/i:EventTrigger&gt;
                      &lt;/i:Interaction.Triggers&gt;
  
                      &lt;DataGrid.Columns&gt;
                          &lt;DataGridTextColumn Header="Symbol"
                                              Binding="{Binding OCSymbol}" /&gt;
                          &lt;DataGridTextColumn Header="Strike"
                                              Binding="{Binding OCStrike}" /&gt;
                          &lt;DataGridTextColumn  Header="Mid"
                                               Binding="{Binding OCMid}" /&gt;
                          &lt;DataGridTextColumn Header="Interest"
                                              Binding="{Binding OCInterest}" /&gt;
                          &lt;DataGridTextColumn Header="Model"
                                              Binding="{Binding OCModel}" /&gt;
                          &lt;DataGridTextColumn Header="Position"
                                              Binding="{Binding OCPosition}" /&gt;
                      &lt;/DataGrid.Columns&gt;
                  &lt;/DataGrid&gt;
              &lt;/StackPanel&gt;
          &lt;/Grid&gt;
      &lt;/GroupBox&gt;
  &lt;/DockPanel&gt;
  </code></pre>
  
  <p>I've tried various approaches like trying to wrap the ListBox in a ScrollViewer, various combinations of setting "CanContentScroll" and nothing seems to result in the horizontal scroll bar being usable.</p>
  
  <p>I even went so far as to create a CustomPanel that implements IScrollInfo hoping that I could get it to scroll the content...that didn't work either.</p>
  
  <p>So...I'm back to pulling hairs and don't have many left!
  Thanks in advance for any help that can be provided.</p>