我有一段由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