2017-06-14 94 views
0

我有一段由List组成的数据,List又有一个List。我如何去显示特定的LeafSide?访问DataGrid中的列表的具体列表

视图模型:

private List<Leaf> _Leaves = new List<Leaf>(); 
    public List<Leaf> Leaves 
    { 
     get { return _Leaves; } 
     set 
     { 
      _Leaves = value; 
      NotifyPropertyChanged(); 
     } 
    } 

数据结构:

class Leaf : NotifyBase 
{ 
    private string _LeafNo; 
    public string LeafNo 
    { 
     get { return _LeafNo; } 
     set 
     { 
      _LeafNo = value; 
      NotifyPropertyChanged(); 
     } 
    } 
    private List<LeafSide> _Side = new List<LeafSide>(); 
    public List<LeafSide> Side 
    { 
     get { return _Side; } 
     set 
     { 
      _Side = value; 
      NotifyPropertyChanged(); 
     } 
    } 
    //More stuff 
} 
class LeafSide : NotifyBase 
{ 
    private string _Notes; 
    public string Notes 
    { 
     get { return _Notes; } 
     set 
     { 
      _Notes = value; 
      NotifyPropertyChanged(); 
     } 
    } 
    //More stuff 
} 

检视:

<DataGrid ItemsSource="{Binding Leaves}"> 
<DataGrid.Columns> 
    <DataGridTextColumn Width="auto" MinWidth="50" Header="Notes" Binding="{Binding Side/Notes}"/> 
    <DataGridTextColumn Width="50" Header="Punch" Binding="{Binding Side/Punch}"/> 
    <!--More--> 
</DataGrid.Columns> 

上述数据网格将显示第一LeafSide完全正常,但我CA不是为了我的生活,弄清楚如何让它显示第二面。我可以找到DataGrids和嵌套列表的所有示例都显示列表中的特定值。 我预计像

<DataGridTextColumn Width="auto" MinWidth="50" Header="Notes" Binding="{Binding Side[1]/Notes}"/> 

工作,但它没有。

编辑更多信息: 我需要的数据网格显示: Seperate DataGrids for Leaf and LeafSide[0] displayed 也为LeafSide [1]

+0

'{装订侧[1] .Notes}'应该工作。如果有更多元素呢? – ASh

+0

@ASh它只是生成一个空白列,其元素数量与LeafNo – AGarcia

+0

@ASh无关,误解您的评论。它工作完美。谢谢。 – AGarcia

回答

0

灰提供了答案,只是重新发布,所以我可以标记为已答复

RIGHT {装订侧[1] .Notes}

WRONG {装订侧[1] /注释}

0

我建议创建一个叫“叶”“SelectedSide”属性,并使用一个对于绑定

private LeafSide _selectedSide;   
    public LeafSide SelectedSide 
    { 
     get { return _selectedSide; } 
     set { _selectedSide = value; NotifyPropertyChanged("SelectedSide"); } 
    } 

我想'[1]'与LeafNo有关。如果是这样设置SelectedSide =边[LeafNo]

<DataGridTextColumn Width="auto" MinWidth="50" Header="Notes" Binding="{Binding SelectedSide.Notes}"/> 
+0

我需要在Side中为每个Leaf显示信息。即:1,/一些笔记/ 2,/一些更多笔记/等等 – AGarcia