Q:

How to bind a Treeview's SelectedItem via DataSource to a Datagrid

I would need to bind selected treeview item (actually datasource of that) to datagrid.
F.ex. I have list of receipts, and under one receipt there is list of receipt-items. I would like to bind those items to datagrid when receipt is selected from treeview.
In datagrid receipt-items would be edited, so values should be bind to actual datasource.
How to do this?

A:

Bind your DataGrids' ItemsSource to the selected Receipt in the Tree:
  <TreeView x:Name="ReceiptsTree" ItemsSource="{Binding Receipts}"/>

  <DataGrid AutoGenerateColumns="False" ItemsSource="{Binding ElementName=ReceiptsTree, Path=SelectedItem.ReceiptItems}">
    <DataGrid.Columns>
      <DataGridTextColumn Header="Receipt Name" Binding="{Binding Name}" />
      .... 
    </DataGrid.Columns>
  </DataGrid>

