简体   繁体   中英

WPF MVVM how to bind Grand Child of an object

I have a document object which contains a collection of lines. for each line in the collection, i have another set of child line collection.

  • Document
    • Lines
      • Child lines

I am trying to bind the lines to a grid and child lines to a separate grid. How to define the binding for the child lines grid?

I know it cant be Document.Lines.ChildLines, may be we need to get the context of the lines and then go to childLines. But im not sure how to do this in WPF. please assist

I managed to get the selected objected and list the lines.

  <DataGrid Name="dgLines"
                              ItemsSource="{Binding Document.Lines}"  
                              AutoGenerateColumns="False" 
                              CanUserAddRows="True" Grid.Row="0" SelectedItem="{Binding SelectedLine}">
  </DataGrid>

 <DataGrid Name="dgChildLines"
                              ItemsSource="{Binding SelectedLine.ChildLines}"  
                              AutoGenerateColumns="False" 
                              CanUserAddRows="True" Grid.Row="2">
 </DataGrid>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM