title: bind VirtualizingStackPanel from code behind
body: <p>I am using this sample to </p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.virtualizingstackpanel.virtualizationmode.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.windows.controls.virtualizingstackpanel.virtualizationmode.aspx</a></p>
  
  <p>but I want to bind my collection on command from the code behind. So basically how to do this with c#?</p>
  
  <pre><code>&lt;StackPanel.Resources&gt;
  &lt;src:LotsOfItems x:Key="data"/&gt;
    &lt;/StackPanel.Resources&gt;
  
    &lt;ListBox Height="150" ItemsSource="{StaticResource data}" 
               VirtualizingStackPanel.VirtualizationMode="Recycling" /&gt;
  </code></pre>