title: WPF: How to bind to only one item in a collection, not using ItemsControl since I don't want to display all of them
body: <p>I have this requirement, that I have a collection of items (ObservableCollection), but I only want to display the first item. The requirement comes from the fact that in most of the case, the collection only contains one item. And due to the space limit, even if there is more than one items in the collection, we'd like to display the number of the items, details of the first one (same presentation as prior situation) and a <code>...</code> symbol to indicate to the user that there is more items. And when the mouse is over the UI element a popup will eventually display all items.</p>
  
  <p>The first solution I can think of (please suggest others if they are better) is to bind to this collection (but not using an <code>ItemsControl</code>) and define a <code>DataTemplateSelector</code> derived class (which return either the <code>DataTemplate</code> to display the only one item, or the <code>DateTemplate</code> which has the <code>...</code> and the popup for more details, based on the number of items in the collection) and use it as <code>ContentTemplateSelector</code>.</p>
  
  <p>But now my question: how both of my <code>DataTemplate</code> would look like in XAML, so that they can display only the first item in the collection? Obviously I can't have a <code>ItemsControl</code>.</p>
  
  <p>UPDATE:</p>
  
  <p>Now I have managed to make it work and agree this question can be closed (I can't delete it anymore since there is already some answers).</p>
  
  <p>I actually knew how to bind to one certain item in the collection, but this was not where I am confused. I felt I should use <code>ContentControl</code> as one answer suggests. But I thought since I need to bind to the whole collection (not to single indexed item), and use a <code>DataTemplateSelector</code> to select the proper <code>DataTemplate</code> based on the number of items in the collection. The code would look like this:</p>
  
  <pre><code>&lt;ContentControl Content="{Binding MyCollection}"
            ContentTemplateSelector="{StaticResource MyTemplateSelector}" /&gt;
  </code></pre>
  
  <p>And in <code>MyTemplateSelector</code> I wasn't sure how to use it since there is no reference to my collection because it is defined as resource and it doesn't have the information of <code>MyCollection</code>. However, it turned out to be very simple, the <code>DataTemplate</code> can refer to an indexed item without knowing the name or any other reference. Simply like this:</p>
  
  <pre><code>&lt;DataTemplate&gt;
     &lt;TextBlock Text="{Binding [0].PropertyName}" /&gt;
  &lt;DataTemplate /&gt;
  </code></pre>