title: ItemsControl only shows first item
body: <p>I suspect the answer to my problem is pretty simple but I have had a good look around the forum and can't seem to find anything quite the same.</p>
  
  <p>I have a reasonably complex binding structure with a ItemsControl at the far end but it only shows the first item. I can see the data on the code side is correct and holds only 8 items, the first item is displayed correctly with all labeling and colours as required.</p>
  
  <p>The logic side structure is like:</p>
  
  <ul>
  <li>MainWindow Partial Class
  <ul>
  <li>ObservableCollection of WaterSamplerClass
  <ul>
  <li>ParametersClass (single instance of a class)
  <ul>
  <li>ObservableCollection of bottleStateClass
  <ul>
  <li>int Number (Property)</li>
  <li>string Label (Property)</li>
  </ul></li>
  </ul></li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>The XAML structure is like:</p>
  
  <ul>
  <li>MainWindow Partial Class
  <ul>
  <li>ControlTemplate GroupBox (DataContext WaterSampler instance from the list set in code)
  <ul>
  <li>DataTemplate containing button that uses bottleState control template</li>
  <li>ItemsControl using DataTemplate to show lots of bottleStates</li>
  </ul></li>
  <li>ControlTemplate containing the decoration of the Button used in the ItemsControl</li>
  </ul></li>
  </ul>
  
  <p>Here's a simplified version of the code:</p>
  
  <p>Items control and its data template inside the GroupBox ControlTemplate whose datacontext is an instance of WaterSampler.</p>
  
  <pre><code>&lt;ControlTemplate x:Key="WaterSamplerGroupBoxTemplate" TargetType="{x:Type GroupBox}" &gt;
     &lt;GroupBox Header="{Binding Path=Header}" Width="300" Margin="10,5,10,0" HorizontalAlignment="Center"&gt;
      &lt;StackPanel Orientation="Horizontal"&gt;
        &lt;StackPanel.Resources&gt;
           &lt;DataTemplate x:Key="BottleStateDataTemplate"&gt;
                 &lt;Button Template="{DynamicResource ValveStatusTemplate}" /&gt;
           &lt;/DataTemplate&gt;
        &lt;/StackPanel.Resources&gt;
      &lt;ItemsControl Name="bottleStateListBox" ItemTemplate="{StaticResource BottleStateDataTemplate}" Margin="5" Height="50" ItemsSource="{Binding BottleIsFullList}" DataContext="{Binding Parameters}"/&gt;
      &lt;/StackPanel&gt;
    &lt;/GroupBox&gt;
  &lt;/ControlTemplate&gt;
  </code></pre>
  
  <p>The simplified button control template:</p>
  
  <pre><code>&lt;ControlTemplate x:Key="ValveStatusTemplate" TargetType="{x:Type Button}" &gt;
        &lt;StackPanel Orientation="Vertical" Width="30" Margin="5" &gt;           
             &lt;TextBlock Text="{Binding Number}" FontSize="18" Canvas.Left="8"/&gt;
        &lt;/StackPanel&gt;
  &lt;/ControlTemplate&gt;
  </code></pre>
  
  <p>The class that holds the data for the item template:</p>
  
  <pre><code>public class DisplayBottleStateClass : INotifyPropertyChanged
  {
      private int number;
      public int Number
      {
          get { return number; }
      }
  }
  </code></pre>
  
  <p>The class containing the list of DisplayBottleClass:</p>
  
  <pre><code>public class WSParametersClass : INotifyPropertyChanged
  {
      private List&lt;DisplayBottleStateClass&gt; bottleIsFullList = new List&lt;DisplayBottleStateClass&gt;();
  
      public List&lt;DisplayBottleStateClass&gt; BottleIsFullList
      {
          get { return bottleIsFullList; }
      }
  }
  </code></pre>
  
  <p>The class containing the parameters class:</p>
  
  <pre><code>public class WaterSampler : INotifyPropertyChanged
  {
      private WSParametersClass parameters = new WSParametersClass();
  
      public WSParametersClass Parameters
      {
          get { return parameters; }
          set { parameters = value; OnPropertyChanged("Parameters"); }
      }
  }
  </code></pre>
  
  <p>Finally the MainWindow class:</p>
  
  <pre><code>public partial class MainWindow : Window
  {
      public class WaterSamplerListClass : ObservableCollection&lt;WaterSampler&gt; { }
      private WaterSamplerListClass waterSamplers = new WaterSamplerListClass();
      public MainWindow()
      {
          waterSamplers.Add(new WaterSampler(0));
          WaterSampler0Group.DataContext = (waterSamplers[0]);
      }
  }
  </code></pre>
  
  <p>I do get a binding error for the two brushes that I use but when I replace these with fixed values in the XAML still only the first element is displayed. The list also seems to update correctly through the binding as I can see the first element changing correctly. The error I get is:</p>
  
  <blockquote>
    <p>System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=GradientStopHighlight; DataItem=null; target element is 'GradientStop' (HashCode=23577486); target property is 'Color' (type 'Color')</p>
  </blockquote>
  
  <p>Any suggestions would be very welcome. </p>
  
  <p>Thanks very much</p>
  
  <p>Ed</p>