title: Source for CompositeCollection: why can't I bind against the data context of another control but have to use a CollectionViewSource?
body: <p>In <a href="https://stackoverflow.com/q/25413252/779395">another question I recently asked</a>, I was told to use a <code>CompositeCollection</code> in order to access various sources for a <code>ListBox</code>.</p>
  
  <p>The example used a <code>XmlDataProvider</code> to provide some dummy data. I, however, have a view model, which contains the data.</p>
  
  <p>It took me some time to bind my <code>ListBox</code> against the view model's data. Eventually I figured it out, but now I'd like to understand why my previous approaches didn't work.</p>
  
  <p>The key to success was a CollectionViewSource. My initial attempts were:</p>
  
  <pre><code>&lt;CollectionContainer Collection="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.Movies}"/&gt;
  &lt;CollectionContainer Collection="{Binding ElementName=Window, Path=DataContext.Movies}"/&gt;
  </code></pre>
  
  <p>My idea was to find the Window, which has the appropriate DataContext, and bind against the data. You can do that via <code>FindAncestor</code> or via <code>ElementName</code>, so I tried both. That seemed very logically to me, but apparently I was wrong. I didn't see nothing when I ran the application.<br>
  I also tried binding against another control which has the data context; e.g. the <code>StackPanel</code>.</p>
  
  <p>So, why don't I get the data with <code>FindAncestor</code> and <code>ElementName</code><sup>1</sup>, but have to provide a <code>CollectionViewSource</code> explicitly?</p>
  
  <hr>
  
  <p>Here's the code that is working.</p>
  
  <pre><code>&lt;StackPanel DockPanel.Dock="Top"&gt;
      &lt;ListBox ItemTemplateSelector="{StaticResource CustomDataTemplateSelector}"&gt;
          &lt;ListBox.Resources&gt;
              &lt;CollectionViewSource x:Key="ViewSource" Source="{Binding Movies}"/&gt;
          &lt;/ListBox.Resources&gt;
          &lt;ListBox.ItemsSource&gt;
              &lt;CompositeCollection&gt;
                  &lt;CollectionContainer Collection="{Binding Source={StaticResource ViewSource}}"/&gt;
                  &lt;CollectionContainer Collection="{Binding Source={StaticResource MyButtonsData}}"/&gt;
              &lt;/CompositeCollection&gt;
          &lt;/ListBox.ItemsSource&gt;
          &lt;ListBox.ItemsPanel&gt;
              &lt;ItemsPanelTemplate&gt;
                  &lt;WrapPanel IsItemsHost="True"
                     Width="{Binding (FrameworkElement.ActualWidth),
                                 RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"/&gt;
              &lt;/ItemsPanelTemplate&gt;
          &lt;/ListBox.ItemsPanel&gt;
      &lt;/ListBox&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <hr>
  
  <p><sup>1</sup> No, I didn't forget to name the window and there wasn't a typo either.</p>