访问 DataGrid 中的特定列表列表
Access specific list of lists in a DataGrid
我有一段数据是由List组成的,List又是一个List。如何显示特定的 LeafSide?
视图模型:
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>
上面的 DataGrid 可以很好地显示第一个 LeafSide,但我终究无法弄清楚如何让它显示第二个面。我能找到的有关 DataGrid 和嵌套列表的所有示例都是显示列表中的特定值。
我期待
<DataGridTextColumn Width="auto" MinWidth="50" Header="Notes" Binding="{Binding Side[1]/Notes}"/>
工作,但没有。
编辑 更多信息:
我需要 DataGrid 来显示:
Seperate DataGrids for Leaf and LeafSide[0] displayed
还有 LeafSide[1]
我建议在 'Leaf' 中创建一个名为 'SelectedSide' 的 属性 并将其用于绑定
private LeafSide _selectedSide;
public LeafSide SelectedSide
{
get { return _selectedSide; }
set { _selectedSide = value; NotifyPropertyChanged("SelectedSide"); }
}
我猜“[1]”与 LeafNo 相关。如果是这样设置 SelectedSide=Sides[LeafNo]
<DataGridTextColumn Width="auto" MinWidth="50" Header="Notes" Binding="{Binding SelectedSide.Notes}"/>
ASh 提供了答案,只是重新发布所以我可以标记为已回答
正确
{装订面[1].Notes}
错误
{装订面[1]/注释}
我有一段数据是由List组成的,List又是一个List。如何显示特定的 LeafSide?
视图模型:
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>
上面的 DataGrid 可以很好地显示第一个 LeafSide,但我终究无法弄清楚如何让它显示第二个面。我能找到的有关 DataGrid 和嵌套列表的所有示例都是显示列表中的特定值。 我期待
<DataGridTextColumn Width="auto" MinWidth="50" Header="Notes" Binding="{Binding Side[1]/Notes}"/>
工作,但没有。
编辑 更多信息: 我需要 DataGrid 来显示: Seperate DataGrids for Leaf and LeafSide[0] displayed 还有 LeafSide[1]
我建议在 'Leaf' 中创建一个名为 'SelectedSide' 的 属性 并将其用于绑定
private LeafSide _selectedSide;
public LeafSide SelectedSide
{
get { return _selectedSide; }
set { _selectedSide = value; NotifyPropertyChanged("SelectedSide"); }
}
我猜“[1]”与 LeafNo 相关。如果是这样设置 SelectedSide=Sides[LeafNo]
<DataGridTextColumn Width="auto" MinWidth="50" Header="Notes" Binding="{Binding SelectedSide.Notes}"/>
ASh 提供了答案,只是重新发布所以我可以标记为已回答
正确 {装订面[1].Notes}
错误 {装订面[1]/注释}