我有一段由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]
'{裝訂側[1] .Notes}'應該工作。如果有更多元素呢? – ASh
@ASh它只是生成一個空白列,其元素數量與LeafNo – AGarcia
@ASh無關,誤解您的評論。它工作完美。謝謝。 – AGarcia