DataGrid RowDetailsTemplate绑定在主数据上下文中查找
本文关键字:上下文 查找 数据 RowDetailsTemplate 绑定 DataGrid | 更新日期: 2023-09-27 18:00:24
有些显而易见的事情,但我被困在这里了。。
我想在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
对象的集合,我认为它们绑定正确。
VM伪码:
class MyViewModel
{
public List<RNPPayPlanLane> RNPPayPlanLanes { get; set; }
}
class RNPPayPlanLane
{
public List<RNPPayPlanLaneDistance> RNPPayPlanLaneDistances { get; set; }
}
class RNPPayPlanLaneDistance {}
RNPPayPlanLane
具有集合属性"RNPPayPlanLaneDistances",我正试图将其用于嵌套网格。这行不通。我得到错误:
系统。Windows。数据错误:BindingExpression路径错误:在"MyViewModel"上找不到"RNPPayPlanLaneDistances"属性
所以,它并没有绑定到"当前项",而是试图绑定到我的主DataContext。为什么?我做错了什么?
我使用telerik的分层网格。我需要定义一个层次结构,没有使用RowDetailsTemplate,但您的错误表明属性丢失,因此,
据我所知
每个车道数据都有一个RNPPayPlanLane1-1
每个RNPPayPlanLane都有许多RNPPayPlannLane距离1-N(主细节)
就好像它应该是那样,
ItemsSource="{Binding RNPPayPlanLane.RNPPayPlanLaneDistances}">