2017-06-14 46 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