title: ListBox.ItemContainerGenerator.ContainerFromIndex Returns null
body: <p>For my Windows Phone 8 App I have a Listbox element like below;
  when I press multiselect icon on AppBar, I want to show checkboxes inside DataTemplate.
  So users can make multiselect on items. </p>
  
  <p>I have 50 elements bound on this Listbox and always at the index 11 <strong>ItemContainerGenerator.ContainerFromIndex</strong> returns null, plus some other items at rest of the list. So around 10 items out of 50 as returning as null.</p>
  
  <p>There are some answers for WPF like applying Dispatcher.BeginInvoke or UpdateLayout, ScrollIntoView but none of them is working.</p>
  
  <p>On the other hand if I scroll through list and then press AppBar icon it just works fine. But users can directly press on icon right after data bound and they will not see some of the checkboxes.</p>
  
  <p>Is there any workaround for this issue for Windows Phone 8?</p>
  
  <pre><code> &lt;ListBox Name="ResultListBox" ItemsSource="{Binding}" 
                   SelectionChanged="ResultListBox_OnSelectionChanged"&gt;
              &lt;ListBox.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;StackPanel Margin="0,0,0,10" Orientation="Horizontal"&gt;
                          &lt;StackPanel Orientation="Horizontal"&gt;
                              &lt;CheckBox Name="CheckBox" Visibility="Collapsed"&gt;
                              &lt;/CheckBox&gt;
                              &lt;Image Source="{Binding url}" 
                                     Width="125" 
                                     Height="125" 
                                     VerticalAlignment="Top" 
                                     Margin="0,0,5,0"&gt;&lt;/Image&gt;
                          &lt;/StackPanel&gt;
                          &lt;StackPanel&gt;
                              &lt;StackPanel Orientation="Horizontal"&gt;
                                  &lt;TextBlock Text="{Binding title}" 
                                             VerticalAlignment="Top" 
                                             FontFamily="Portable User Interface"&gt;&lt;/TextBlock&gt;
                              &lt;/StackPanel&gt;
                              &lt;StackPanel&gt;
                                  &lt;TextBlock Text="{Binding description}" 
                                             FontFamily="Portable User Interface"&gt;&lt;/TextBlock&gt;
                              &lt;/StackPanel&gt;
                          &lt;/StackPanel&gt;
                      &lt;/StackPanel&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ListBox.ItemTemplate&gt;
          &lt;/ListBox&gt;
  
  
  
  
  void appBarButtonSelect_Click(object sender, EventArgs e)
      {
          //Dispatcher.BeginInvoke(delegate
          //{
          //});
          for (int i = 0; i &lt; ResultListBox.Items.Count; i++)
          {
              //ResultListBox.UpdateLayout();
              //ResultListBox.ScrollIntoView(i);
              DependencyObject item = ResultListBox.ItemContainerGenerator.ContainerFromIndex(i);
              if (item != null)
              {
                  CheckBox checkBox = FindFirstElementInVisualTree&lt;CheckBox&gt;(item);
                  if (checkBox != null)
                  {
                      checkBox.Visibility = Visibility.Visible;
                  }
              }
              else
              {
                  Debugger.Break();
              }
          }
      }
  </code></pre>