title: WPF Accessing Items inside Listbox which has a UserControl as ItemTemplate
body: <ul>
  <li>I have Window that has a ListBox</li>
  <li>ListBox(MyListBox) has a DataTable for its DataContext</li>
  <li>ListBox's ItemSource is : {Binding}</li>
  <li>Listbox has a UserControl(MyUserControl) as DataTemplate</li>
  <li>UserControl has RadioButtons and TextBoxes (At first They're filled with values from DataTable and then user can change them)</li>
  <li>Window has one Submit Button</li>
  </ul>
  
  <p>What I want to do is, when user clicks the submit button </p>
  
  <ul>
  <li>For each ListBox Item, get the values form UserControl's TextBoxes and RadioButtons.</li>
  </ul>
  
  <p>I was using that method for this job :</p>
  
  <pre><code>foreach(var element in MyListBox.Items)
  { 
    var border = MyListBox.ItemContainerGenerator.ContainerFromItem(element)as FrameworkElement;
    MyUserControl currentControl = VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(myBorder,0) as Border,0)as ContentPresenter,0)as MyUserControl;
    //And use currentControl
  }
  </code></pre>
  
  <p>I realised nothing when using 3-5 items in Listbox. But when I used much more items, I saw that "var border" gets "null" after some elements looped in foreach function.</p>
  
  <p>I found the reason here :
  <a href="https://stackoverflow.com/questions/1675926/listview-itemcontainergenerator-containerfromitemitem-return-null-after-20-item">ListView.ItemContainerGenerator.ContainerFromItem(item) return null after 20 items</a></p>
  
  <p>So what can I do now? I want to access all items and get their values sitting on user controls.</p>
  
  <p>Thanks</p>