显而易见的事情,但我被困在这里..
我想在 DataGrid 中显示 DataGrid,这里是 XAML:
<sdk:DataGrid
ItemsSource="{Binding RNPPayPlanLanes}"
RowDetailsVisibilityMode="Visible">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="From region" Binding="{Binding FromRegionKey, Mode=TwoWay}" />
<sdk:DataGridTextColumn Header="To region" Binding="{Binding ToRegionKey, Mode=TwoWay}" />
</sdk:DataGrid.Columns>
<sdk:DataGrid.RowDetailsTemplate>
<DataTemplate>
<sdk:DataGrid
HorizontalAlignment="Right"
ItemsSource="{Binding RNPPayPlanLaneDistances}">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="UpToDistance" Binding="{Binding UpToDistance, Mode=TwoWay}" />
<sdk:DataGridTextColumn Header="PayPerDistanceUnitAmount" Binding="{Binding PayPerDistanceUnitAmount, Mode=TwoWay}" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
</DataTemplate>
</sdk:DataGrid.RowDetailsTemplate>
</sdk:DataGrid>
MyViewModel 包含RNPPayPlanLane
对象集合,我看到它们正确绑定。
虚拟机伪代码:
class MyViewModel
{
public List<RNPPayPlanLane> RNPPayPlanLanes { get; set; }
}
class RNPPayPlanLane
{
public List<RNPPayPlanLaneDistance> RNPPayPlanLaneDistances { get; set; }
}
class RNPPayPlanLaneDistance {}
RNPPayPlanLane
有我试图用于嵌套网格的集合属性“RNPPayPlanLaneDistances”。这行不通。我得到错误:
System.Windows.Data 错误:BindingExpression 路径错误:在“MyViewModel”上找不到“RNPPayPlanLaneDistances”属性
因此,它没有绑定到“当前项目”,而是试图绑定到我的主 DataContext。为什么?我做错了什么?