简体   繁体   English

WPF MVVM如何绑定对象的子代

[英]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. 我知道它不能是Document.Lines.ChildLines,可能是我们需要获取行的上下文,然后转到childLines。 But im not sure how to do this in WPF. 但是我不确定如何在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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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