title: Getting UI virtualization working with ItemsControl in Silverlight
body: <p>I'm trying to create a scrolling list of fairly large textblocks.  I want there to be a vertical scrollbar to show them all, and if they overflow a certain size I want them to display an ellipsis.  I actually have all this working pretty good.</p>
  
  <p>I have the following Silverlight XAML:</p>
  
  <pre><code>&lt;Grid x:Name="LayoutRoot" MaxWidth="500" MinWidth="100"
      MaxHeight="500" MinHeight="100"&gt;
      &lt;Grid.DataContext&gt;
          &lt;app:MainPageViewModel/&gt;
      &lt;/Grid.DataContext&gt;
      &lt;ScrollViewer&gt;
      &lt;ItemsControl ItemsSource="{Binding TextItems}" Margin="0,20,0,20"&gt;
          &lt;ItemsControl.ItemTemplate&gt;&lt;DataTemplate&gt;
              &lt;Border MaxHeight="175" Margin="0,0,0,18" CornerRadius="5"&gt;
                  &lt;TextBlock Margin="2" TextTrimming="WordEllipsis"
                       TextWrapping="Wrap" Text="{Binding}"/&gt;
              &lt;/Border&gt;
           &lt;/DataTemplate&gt;&lt;/ItemsControl.ItemTemplate&gt;
      &lt;/ItemsControl&gt;
      &lt;/ScrollViewer&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>My problem is that this layout does not use UI virtualization, such as with a VirtualizingStackPanel.  So it is pretty slow.  What is the best way to get UI virtualization into this layout?  I've tried about a half dozen different ways and nothing has worked out all that well.</p>
  
  <p>I managed to get this working in a ListBox because it seems to support virtualization out of the box.  However, I'd prefer to use ItemsControl as I don't want these things to be selectable, and I don't want the styling that comes along with a ListBox.</p>
  
  <p>This in Silverlight 4.</p>