title: ScrollIntoView and ListView with virtualization
body: <p>I have <code>ListView</code> (virtualization is on by default), which <code>ItemsSource</code> is bound to <code>ObservableCollection&lt;Item&gt;</code> property.</p>
  
  <p>When data are populated (property is set and notification is rised) I see 2 layout spikes in profiler, second one happens after call <code>listView.ScrollIntoView()</code>.</p>
  
  <p>My understanding is:</p>
  
  <ol>
  <li><code>ListView</code> loads data via binding and creates <code>ListViewItem</code> for items on screen, starting from index 0.</li>
  <li>Then I call <code>listView.ScrollIntoView()</code>.</li>
  <li>And now <code>ListView</code> does that second time (creating <code>ListViewItem</code>s).</li>
  </ol>
  
  <p>How do I prevent that de-virtualization from happening twice (I don't want one before <code>ScrollIntoView</code> to occur)?</p>
  
  <hr>
  
  <p>I tried to make a repro using <code>ListBox</code>.</p>
  
  <p>xaml:</p>
  
  <pre><code>&lt;Grid&gt;
      &lt;ListBox x:Name="listBox" ItemsSource="{Binding Items}"&gt;
          &lt;ListBox.ItemContainerStyle&gt;
              &lt;Style TargetType="ListBoxItem"&gt;
                  &lt;Setter Property="IsSelected" Value="{Binding IsSelected}" /&gt;
              &lt;/Style&gt;
          &lt;/ListBox.ItemContainerStyle&gt;
      &lt;/ListBox&gt;
      &lt;Button Content="Fill" VerticalAlignment="Top" HorizontalAlignment="Center" Click="Button_Click" /&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>cs:</p>
  
  <pre><code>public class NotifyPropertyChanged : INotifyPropertyChanged
  {
      public event PropertyChangedEventHandler PropertyChanged;
      public void OnPropertyChanged([CallerMemberName] string property = "") =&gt; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
  }
  
  public class ViewModel : NotifyPropertyChanged
  {
      public class Item : NotifyPropertyChanged
      {
          bool _isSelected;
          public bool IsSelected
          {
              get { return _isSelected; }
              set
              {
                  _isSelected = value;
                  OnPropertyChanged();
              }
          }
      }
  
      ObservableCollection&lt;Item&gt; _items = new ObservableCollection&lt;Item&gt;();
      public ObservableCollection&lt;Item&gt; Items
      {
          get { return _items; }
          set
          {
              _items = value;
              OnPropertyChanged();
          }
      }
  }
  
  public partial class MainWindow : Window
  {
      ViewModel _vm = new ViewModel();
  
      public MainWindow()
      {
          InitializeComponent();
          DataContext = _vm;
      }
  
      void Button_Click(object sender, RoutedEventArgs e)
      {
          var list = new List&lt;ViewModel.Item&gt;(1234567);
          for (int i = 0; i &lt; 1234567; i++)
              list.Add(new ViewModel.Item());
          list.Last().IsSelected = true;
          _vm.Items = new ObservableCollection&lt;ViewModel.Item&gt;(list);
          listBox.ScrollIntoView(list.Last());
      }
  }
  </code></pre>
  
  <p>Debug - Performance Profiler - Application Timeline... wait a bit, click button, wait a bit, close window. You will see 2 layout passes with <code>VirtualizingStackPanel</code>. My aim is to have just one and I don't know how.</p>
  
  <p>The problem with repro is to simulate load (when creating <code>ListViewItem</code> <a href="https://stackoverflow.com/q/38307477/1997232">is expensive</a>), but I hope it's more clearly demonstrate the problem now.</p>