title: XAML binding to CompositeCollection
body: <p>I have only one datagrid in a single view but the collections which are ItemsSource's of this datagrid are in different View Models. So is it possible to bind this single datagrid in view with the collections in two different View Models? </p>
  
  <p>For each row in the grid, display an item from one collection, and an item from the other collection..! to display all columns in one row. </p>
  
  <p>xaml: </p>
  
  <pre><code>DataContext="{DynamicResource ViewModelCombine}"&gt; 
  
  &lt;Window.Resources&gt; 
      &lt;vm:ViewModelCombine x:Key="ViewModelCombine"/&gt; 
  &lt;/Window.Resources&gt; 
  
  &lt;Grid&gt; 
          &lt;Grid.RowDefinitions&gt; 
              &lt;RowDefinition Height="Auto"/&gt; 
          &lt;/Grid.RowDefinitions&gt; 
  
       &lt;DataGrid&gt; 
  
              &lt;DataGrid.Resources&gt;
                  &lt;CollectionViewSource x:Key="ViewModelPulse" Source="{Binding VP}"/&gt;
                  &lt;CollectionViewSource x:Key="ViewModeltherapy" Source="{Binding VT}"/&gt;
              &lt;/DataGrid.Resources&gt;
  
              &lt;DataGrid.ItemsSource&gt; 
                  &lt;CompositeCollection&gt; 
                      &lt;CollectionContainer Collection="{Binding Source={StaticResource ViewModelCombine}, Path=VP}" /&gt; 
                      &lt;CollectionContainer Collection="{Binding Source={StaticResource ViewModelCombine}, Path=VT}" /&gt; 
                  &lt;/CompositeCollection&gt; 
              &lt;/DataGrid.ItemsSource&gt; 
  
              &lt;DataGrid.Columns&gt; 
                  &lt;DataGridTextColumn Header="AMP" Binding="{Binding AMP}" Width="100"/&gt; 
                  &lt;DataGridTextColumn Header="PW" Binding="{Binding PW}" Width="100" /&gt; 
                  &lt;DataGridTextColumn Header="DZ0" Binding="{Binding DZ0}" Width="100" /&gt; 
                  &lt;DataGridTextColumn Header="DELTA" Binding="{Binding DELTA}" Width="100" /&gt; 
                  &lt;DataGridTextColumn Header="DZ1" Binding="{Binding DZ1}"   Width="100"/&gt; 
                  &lt;DataGridTextColumn Header="M" Binding="{Binding M}" Width="100" /&gt; 
                  &lt;DataGridTextColumn Header="DZ2" Binding="{Binding DZ2}" Width="100" /&gt; 
                  &lt;DataGridTextColumn Header="N" Binding="{Binding N}" Width="100" /&gt; 
              &lt;/DataGrid.Columns&gt; 
  
      &lt;/DataGrid&gt; 
  
  &lt;/Grid&gt; 
  </code></pre>
  
  <p>xaml.cs: </p>
  
  <pre><code>public MainWindow() 
  { 
      InitializeComponent(); 
      ViewModelCombine VMC = new ViewModelCombine(); 
      this.DataContext = VMC; 
  } 
  </code></pre>
  
  <p>ViewModelCombine.cs</p>
  
  <pre><code>public class ViewModelCombine 
  { 
      public ViewModelTherapy VT { get; set; } 
      public ViewModelPulse VP { get; set; }
  
      public ViewModelCombine() 
      { 
          VT = new ViewModelTherapy(); 
          VP = new ViewModelPulse(); 
      } 
  
  } 
  </code></pre>
  
  <p>As per the above code, it displays like this <a href="https://i.stack.imgur.com/EsRUF.png" rel="nofollow">Output</a>..but, wanted to display all columns in one row.</p>
  
  <p>So is it possible to bind this single datagrid in view with the collections in two different View Models?</p>
  
  <p>Thanks for your help.</p>