我有DataGrid
显示项目列表,每个项目可能都有详细信息,这是我的代码:
<DataGrid x:Name="dgItemsReceipt" CanUserAddRows="True" ItemsSource="{Binding ocItemsinInvoice,Mode=TwoWay}">
<DataGrid.Columns>
<DataGridTextColumn Header="Item" Binding="{Binding Item.ItemName}" Width="*" IsReadOnly="True"/>
<DataGridTextColumn Header="Price" Binding="{Binding SalePrice,Mode=TwoWay}" Width="100" IsReadOnly="False" />
<DataGridTextColumn Header="Qnt" Binding="{Binding Quantity,Mode=TwoWay}" Width="100" IsReadOnly="False" />
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<TextBlock Text="{Binding ItemsInInvoiceChoices.ChoicesId}" />
</DataTemplate>
</DataGrid.RowDetailsTemplate>
ItemsInInvoiceChoices是与ItemsinInvoice相关的表。
现在,当我添加Item并为其添加Choice时,Item出现在数据网格中,但现在显示详细信息了?
答案 0 :(得分:0)
尝试:
<DataGrid.Columns>
<DataGridTextColumn Header="Item Name" Binding="{Binding Item.ItemName}" Width="*" IsReadOnly="True"/>
<DataGridTextColumn Header="Price" Binding="{Binding SalePrice,Mode=TwoWay}" Width="100" IsReadOnly="False" />
<DataGridTextColumn Header="Quantity" Binding="{Binding Quantity,Mode=TwoWay}" Width="100" IsReadOnly="False" />
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<ListBox ItemsSource="{Binding {RelativeSource FindAncestor, AncestorType=DataGrid}, Path=ocChoiceRecord, ElementName=myRoot}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding RecordDescription}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
答案 1 :(得分:0)
这里myRoot
是什么?你不需要在这里给ElementName
。如果ocChoiceRecord
是ocItemsinInvoice
集合项的属性。你可以直接绑定它,如下所示。这样,每个行细节都将绑定到其Item。
<ListBox ItemsSource="{Binding ocChoiceRecord}">