title: ListBox ScrollIntoView and SelectedItem unreliable
body: <p>I currently have a list box set up as follows:</p>
  
  <p>.xaml:</p>
  
  <pre><code>&lt;ListBox Name="DetailsList" ItemsSource="{Binding}" LayoutUpdated="DetailsList_LayoutUpdated" /&gt;
  </code></pre>
  
  <p>.xaml.cs:</p>
  
  <pre><code>private ObservableCollection&lt;string&gt; details = new ObservableCollection&lt;string&gt;();
  </code></pre>
  
  <p>In the window constructor:</p>
  
  <pre><code>DetailsList.DataContext = details;
  </code></pre>
  
  <p>I had a button that did the following:</p>
  
  <pre><code>details.Add(System.DateTime.Now.ToString("HH:mm:ss ") + someString);
  DetailsList.UpdateLayout();
  var lastItem = DetailsList.Items[DetailsList.Items.Count - 1];
  DetailsList.SelectedItem = lastItem;
  DetailsList.ScrollIntoView(lastItem);
  </code></pre>
  
  <p>That <em>should</em> select the last item in the list and scroll to it, but it only does it around 75% of the time. Instead, it will often select the second last and scroll to that instead.</p>
  
  <p>I tried moving the scroll and selection into a LayoutUpdated event handler, no change.</p>
  
  <p>I tried two separate buttons - one to add, one to select and scroll. If I add one item at a time then scroll, it seems to be slightly more reliable - it works 90% of the time. If I add half a dozen items before scrolling, it almost never works. It will typically select one of the new items, but not the last one.</p>
  
  <p>Am I doing something wrong, or is there a bug with System.Windows.Controls.ListBox?</p>