title: How Do I Bind a "selected Item" in a Listbox to a ItemsControl in WPF?
body: <p>LowDown: I am trying to create a Document Viewer in WPF. It will allow the user to preview selected documents and if they want, compare the documents in WPF. So they can view them side by side.</p>
  
  <p>The layout is this: Left side is a full list box.  On the right side is a Collection or an Items control.  Inside the items control will be a collection of the "selected documents" in the list box.  So A user can select multiple items in the list box and for each new item they select, they can add the item to the collection on the right.  I want the collection to look like a image gallery that shows up in Google/Bing Image searches. Make sense?</p>
  
  <p>The problem I am having is I can't get the WPFPreviewer to bind correctly to the selected item in the list box under the itemscontrol.  </p>
  
  <p><strong>Side Note:</strong> The WPFPreviewer is something Micorosft puts out that allows us to preview documents.  Other previewers can be built for all types of documents, but im going basic here until I get this working right.</p>
  
  <p>I have been successful in binding to the list box WITHOUT the items control here:</p>
  
  <pre><code>&lt;Window.Resources&gt;
      &lt;DataTemplate x:Key="listBoxTemplate"&gt;
          &lt;StackPanel Margin="3" &gt;
              &lt;DockPanel &gt;
                  &lt;Image Source="{Binding IconURL}" Height="30"&gt;&lt;/Image&gt;
                  &lt;TextBlock Text="  " /&gt;
                  &lt;TextBlock x:Name="Title" Text="{Binding Title}" 
                      FontWeight="Bold" /&gt;
                  &lt;TextBlock x:Name="URL" Visibility="Collapsed" 
                      Text="{Binding Url}"/&gt;
              &lt;/DockPanel&gt;
          &lt;/StackPanel&gt;
      &lt;/DataTemplate&gt;
  &lt;/Window.Resources&gt;
  &lt;Grid Background="Cyan"&gt;
      &lt;ListBox HorizontalAlignment="Left" 
          ItemTemplate="{StaticResource listBoxTemplate}" Width="200" 
          AllowDrop="True" x:Name="lbDocuments" 
          ItemsSource="{Binding Path=DocumentElements,ElementName=winDocument}"       
          DragEnter="documentListBox_DragEnter"  /&gt;
      &lt;l:WPFPreviewHandler
          Content="{Binding ElementName=lbDocuments, Path=SelectedItem.Url}"/&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>Though, once I add in the ItemsControl, I can't get it to work anymore:</p>
  
  <pre><code>&lt;Window.Resources&gt;
      &lt;DataTemplate x:Key="listBoxTemplate"&gt;
          &lt;StackPanel Margin="3" &gt;
              &lt;DockPanel &gt;
                  &lt;Image Source="{Binding IconURL}" Height="30"&gt;&lt;/Image&gt;
                  &lt;TextBlock Text="  " /&gt;
                  &lt;TextBlock x:Name="Title" Text="{Binding Title}" FontWeight="Bold" /&gt;
                  &lt;TextBlock x:Name="URL" Visibility="Collapsed" Text="{Binding Url}"/&gt;
              &lt;/DockPanel&gt;
          &lt;/StackPanel&gt;
      &lt;/DataTemplate&gt;
  &lt;/Window.Resources&gt;
  &lt;Grid&gt;
      &lt;ListBox HorizontalAlignment="Left" 
          ItemTemplate="{StaticResource listBoxTemplate}" Width="200" 
          AllowDrop="True" x:Name="lbDocuments" 
          ItemsSource="{Binding Path=DocumentElements,ElementName=winDocument}"
          DragEnter="documentListBox_DragEnter"  /&gt;
      &lt;ItemsControl x:Name="DocumentViewer"  
          ItemsSource="{Binding ElementName=lbDocuments, Path=SelectedItem.Url}" &gt;
          &lt;ItemsControl.ItemTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;Grid Background="Cyan"&gt;
                      &lt;l:WPFPreviewHandler Content="{Binding Url}"/&gt;
                  &lt;/Grid&gt;
              &lt;/DataTemplate&gt;
          &lt;/ItemsControl.ItemTemplate&gt;
      &lt;/ItemsControl&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>Here is the Class of which is loaded into the ListBox</p>
  
  <pre><code>    public class Document
  {
      public string Title { get; set; } 
      public string Url { get; set; } //this is what I want
      public string IconURL { get; set; } //used so I can display the icon of the file
  }
  </code></pre>
  
  <p>Can someone please help me out with trying to bind to the ItemsControl if I select one or even multiple items in the listbox.</p>