我有一个 DataGrid,在那个 DataGrid 的 DataGrid.RowDetailsTemplate 中我放了另一个 DataGrid。现在我的第一个 Datagrid 有 ItemsSource="{Binding MatchObsCollection}" 并且我的 DataGrid.RowDetailsTemplate 中的内部 Datagrid 有单独的 ItemSource。但是内部 Datagrid 没有填充。我正在使用 MVVM,并且我通过 Viewmodel 上的 ObservableCollections 绑定了 Datagrid 。谁能帮助我(我的问题与在 WPF DataGrid 中显示层次父子数据几乎相同, 但我在那篇文章中也没有找到任何好的答案)。我的 xaml 代码附在下面。谢谢,
<DataGrid HorizontalAlignment="Stretch" Margin="0" x:Name="dataGridParent" ItemsSource="{Binding MatchObsCollection}"
Style="{StaticResource EfesDataGridStyle}" FrozenColumnCount="14" GridLinesVisibility="All"
HorizontalGridLinesBrush="#DADADA" VerticalGridLinesBrush="#DADADA" Cursor="Hand" AutoGenerateColumns="False"
RowDetailsVisibilityMode="Visible"
util:ParentMatchDataGridRowClickHandler.MethodName="ParentMatchDatagrdRowClick"
SelectedItem="{Binding SelectedMatch}"
>
<DataGrid.Columns>
<DataGridTextColumn Header="Kod" Binding="{Binding MatchNo}" Width="50*" />
<DataGridTextColumn Header="Tarih" Binding="{Binding MatchDate}" Width="70*"/>
<DataGridTextColumn Header="Ev Sahibi" Binding="{Binding MatchHome}" Width="100*"/>
<DataGridTextColumn Header="Konuk" Binding="{Binding MatchVisitor}" Width="50*"/>
<DataGridTextColumn Header="1" Binding="{Binding MatchResultHomeOdds}" Width="30*" ></DataGridTextColumn>
<DataGridTextColumn Header="X" Binding="{Binding MatchResultDrawOdds}" Width="30*" />
<DataGridTextColumn Header="2" Binding="{Binding MatchResultVisitorOdds}" Width="30*"/>
<DataGridTextColumn Header="T1" Binding="{Binding MatchresultSingleHomeOdds}" Width="30*" />
<DataGridTextColumn Header="TX" Binding="{Binding MatchresultSingleDrawOdds}" Width="30*" />
<DataGridTextColumn Header="T2" Binding="{Binding MatchresultSingleVisitorOdds}" Width="30*" />
<DataGridTextColumn Header="+" CellStyle ="{StaticResource DataGridCellStyle}" Binding="{Binding TotalBets}" Width="30*"/>
<DataGridTextColumn Header="Min" Binding="{Binding MatchMin}" Width="30*" />
<DataGridTextColumn Header="Lig" Binding="{Binding TeamName}" Width="70*" />
<DataGridTemplateColumn Header="Durum" Width="Auto" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ToggleButton x:Name="toggleBtn" VerticalAlignment="Center" Margin="0" Style="{StaticResource SlidingToggleButton}" BorderBrush="{x:Null}" IsChecked="{Binding ToggleBtn}" Background="#FF2F63FF" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate x:Uid="test123">
<DataTemplate x:Name="testTemplete">
<DataGrid x:Name="innerGrid" ItemsSource="{Binding SubBetMatchDataListforChildGrid}"
Style="{StaticResource EfesDataGridStyle}" Margin="50,2,2,2" MinHeight="40"
GridLinesVisibility="All" HorizontalGridLinesBrush="#DADADA" VerticalGridLinesBrush="#DADADA"
Visibility="Collapsed" >
<DataGrid.Columns>
<DataGridTextColumn Header="Kod" Binding="{Binding Code}" Width="3*" />
<DataGridTextColumn Header="Alt Secenakler" Binding="{Binding SubOptions}" Width="7*" />
</DataGrid.Columns>
</DataGrid>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>