title: VirtualizingStackPanel and TextWrapping bug? Windows Phone
body: <p>I have a strange behaviour with <code>VirtualizingStackPanel</code>. I have a list with items that contains <code>TextBlock</code> with <code>TextWrap="Wrap"</code>. Here is the code:</p>
  
  <pre><code>&lt;ListBox x:Name="messagesList" ItemsSource="{Binding Messages}" &gt;
      &lt;ListBox.ItemContainerStyle&gt;
          &lt;Style TargetType="ListBoxItem"&gt;
              &lt;Setter Property="HorizontalContentAlignment" Value="Stretch" /&gt;
          &lt;/Style&gt;
      &lt;/ListBox.ItemContainerStyle&gt;
      &lt;ListBox.ItemTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;StackPanel&gt;
                  &lt;toolkit:ContextMenuService.ContextMenu&gt;
                      &lt;toolkit:ContextMenu&gt;
                      ...
                      &lt;/toolkit:ContextMenu&gt;
                  &lt;/toolkit:ContextMenuService.ContextMenu&gt;
                  &lt;CheckBox Style="{Binding Own, Converter={StaticResource MsgTypeToStyle}}"
                            Tag="{Binding TimeString}"
                            IsEnabled="True"&gt;
                      &lt;TextBlock Text="{Binding Content}" TextWrapping="Wrap"/&gt;
                  &lt;/CheckBox&gt;
              &lt;/StackPanel&gt;
          &lt;/DataTemplate&gt;
      &lt;/ListBox.ItemTemplate&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>It works pretty good, but if I try to scroll very fast (using mouse on emulator, not prommatically) there is some lagging in scroll, probably <code>HorizontallOffset</code> sometimes calculates wrong, and in the bottom in ends with very strange result (see image, right image demostrates normal behaviour).</p>
  
  <p><img src="https://i.stack.imgur.com/C4VZp.jpg" alt="scroll bug"></p>
  
  <p>After research I figured out that problem in combination <code>VirtualizingStackPanel</code> and <code>TextBlock.TextWrap="Wrap"</code>, if I remove one element from this couple all works correctly.</p>
  
  <p>But I need virtualization because of big items count, and <code>TextWrap</code> for correct text displaying.</p>
  
  <p>So I think about making my own implementation of Virtualizing Panel, can you please guide me, how to do this, or how to fix current problem?</p>
  
  <p><strong>UPD: The problem:<br>
  on the first two images <code>ListBox</code> is already(!) scrolled to the bottom (it can't be scrolled down any more), but elements placed incorrectly, correct placing shown on the right image. This happens only if you will scroll very fast.</strong></p>
  
  <p><strong>UPD2: Thanks to Milan Aggarwal. He provided a good case of my problem <a href="http://blog.rsuter.com/?p=258" rel="noreferrer">here</a>. Seems that is really a bug in <code>ListBox</code>. Workaround, provided doesn't fit in my scenario, because I need to interact with controls inside <code>ListBox</code> item. 
  Now I'm trying to catch <code>ManipulationCompleted</code> event and check if it is <code>Inertial</code>, if so that means scroll and I set focus to page:</strong></p>
  
  <pre><code>    void messagesList_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
      {
          if (e.IsInertial)
              this.Focus();
      }
  </code></pre>
  
  <p>P.S. thanks for good luck wishes;)</p>