我有一个父 DataGrid,在那个 DataGrid 里面我有一个内部 DataGrid。我的目标是在我的父 DataGrid 的行单击时填充内部数据网格。下面是我的代码:
<DataGrid ItemsSource="{Binding GuestHostTotalList}" HorizontalAlignment="Stretch" Margin="16,15,-14,-15" x:Name="dataGridParent"
Style="{StaticResource EfesDataGridStyle}" FrozenColumnCount="14" GridLinesVisibility="All"
HorizontalGridLinesBrush="#DADADA" VerticalGridLinesBrush="#DADADA" Cursor="Hand" AutoGenerateColumns="False"
RowDetailsVisibilityMode="Visible" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp">
<ei:CallMethodAction MethodName="UpdateEvent" TargetObject="{Binding}"></ei:CallMethodAction>
</i:EventTrigger>
</i:Interaction.Triggers>
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="Background" Value="Black"></Setter>
<Setter Property="MinHeight" Value="28"></Setter>
<Setter Property="Cursor" Value="Hand"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Border x:Name="BackgroundBorder" BorderThickness="0" Background="{StaticResource Siyah}" BorderBrush="{StaticResource Siyah}" Grid.ColumnSpan="2" />
<ContentPresenter Margin="6,3,6,3" VerticalAlignment="Center" />
<Path x:Name="SortArrow" Visibility="Collapsed" Data="M0,0 L1,0 0.5,1 z" Stretch="Fill" Grid.Column="3" Width="8" Height="6" Fill="White" Margin="0,0,8,0" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.4" />
<Rectangle Width="1" Fill="#AAC377" HorizontalAlignment="Right" Grid.ColumnSpan="2" />
<Rectangle Width="1" Margin="0,0,1,0" Fill="#425B10" HorizontalAlignment="Right" Grid.ColumnSpan="2" />
<Thumb x:Name="PART_LeftHeaderGripper" Visibility="Hidden" HorizontalAlignment="Left" />
<Thumb x:Name="PART_RightHeaderGripper" Visibility="Hidden" HorizontalAlignment="Right" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="SortDirection" Value="{x:Null}">
<Setter TargetName="BackgroundBorder" Property="Background" Value="{DynamicResource Siyah}" />
<Setter TargetName="BackgroundBorder" Property="BorderBrush" Value="Transparent" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="SortDirection" Value="{x:Null}" />
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="BackgroundBorder" Value="{StaticResource ASiyah}" />
<Setter Property="BorderBrush" TargetName="BackgroundBorder" Value="{StaticResource ASiyah}" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="true" />
<Condition Property="SortDirection" Value="{x:Null}" />
</MultiTrigger.Conditions>
<Setter TargetName="BackgroundBorder" Property="Background" Value="{StaticResource ASiyah}" />
<Setter TargetName="BackgroundBorder" Property="BorderBrush" Value="{StaticResource ASiyah}" />
</MultiTrigger>
<Trigger Property="SortDirection" Value="Ascending">
<Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
<Setter TargetName="SortArrow" Property="RenderTransform">
<Setter.Value>
<RotateTransform Angle="180" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="SortDirection" Value="Descending">
<Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger Property="DisplayIndex" Value="0">
<Setter Property="Visibility" Value="Collapsed" TargetName="PART_LeftHeaderGripper"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="LightGray" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Kod" Binding="{Binding Code}" Width="50*" />
<DataGridTextColumn Header="Tarih" Binding="{Binding History}" Width="70*"/>
<DataGridTextColumn Header="Ev Sahibi" Binding="{Binding Own}" Width="100*"/>
<DataGridTextColumn Header="Konuk" Binding="{Binding Guest}" Width="50*"/>
<DataGridTextColumn Header="1" Binding="{Binding One_guest}" Width="30*" />
<DataGridTextColumn Header="X" Binding="{Binding X_game}" Width="30*" />
<DataGridTextColumn Header="2" Binding="{Binding Two_guest}" Width="30*"/>
<DataGridTextColumn Header="T1" Binding="{Binding T1_host}" Width="30*" />
<DataGridTextColumn Header="TX" Binding="{Binding TX_host}" Width="30*" />
<DataGridTextColumn Header="T2" Binding="{Binding T2_host}" Width="30*" />
<DataGridTextColumn Header="+" CellStyle ="{StaticResource DataGridCellStyle}" Binding="{Binding TotalOptions}" Width="30*"/>
<DataGridTextColumn Header="Min" Binding="{Binding MinOption}" Width="30*" />
<DataGridTextColumn Header="Lig" Binding="{Binding League}" 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.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<EventSetter Event="MouseLeftButtonUp" Handler="RowClick"/>
</Style>
</DataGrid.RowStyle>
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"/>
</DataGrid.Resources>
<DataGrid.RowDetailsTemplate x:Uid="test123">
<DataTemplate x:Name="testTemplete">
<DataGrid x:Name="innerGrid" ItemsSource="{Binding SubGridItemList}" Style="{StaticResource EfesDataGridStyle}" Margin="50,2,2,2" MinHeight="40" GridLinesVisibility="All" HorizontalGridLinesBrush="#DADADA" VerticalGridLinesBrush="#DADADA" Visibility="Collapsed" >
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="Background" Value="Black"></Setter>
<Setter Property="MinHeight" Value="28"></Setter>
<Setter Property="Cursor" Value="Hand"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Border x:Name="BackgroundBorder" BorderThickness="0" Background="{StaticResource Siyah}" BorderBrush="{StaticResource Siyah}" Grid.ColumnSpan="2" />
<ContentPresenter Margin="6,3,6,3" VerticalAlignment="Center" />
<Path x:Name="SortArrow" Visibility="Collapsed" Data="M0,0 L1,0 0.5,1 z" Stretch="Fill" Grid.Column="3" Width="8" Height="6" Fill="White" Margin="0,0,8,0" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.4" />
<Rectangle Width="1" Fill="#AAC377" HorizontalAlignment="Right" Grid.ColumnSpan="2" />
<Rectangle Width="1" Margin="0,0,1,0" Fill="#425B10" HorizontalAlignment="Right" Grid.ColumnSpan="2" />
<Thumb x:Name="PART_LeftHeaderGripper" Visibility="Hidden" HorizontalAlignment="Left" />
<Thumb x:Name="PART_RightHeaderGripper" Visibility="Hidden" HorizontalAlignment="Right" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="SortDirection" Value="{x:Null}">
<Setter TargetName="BackgroundBorder" Property="Background" Value="{DynamicResource Siyah}" />
<Setter TargetName="BackgroundBorder" Property="BorderBrush" Value="Transparent" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="SortDirection" Value="{x:Null}" />
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="BackgroundBorder" Value="{StaticResource ASiyah}" />
<Setter Property="BorderBrush" TargetName="BackgroundBorder" Value="{StaticResource ASiyah}" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="true" />
<Condition Property="SortDirection" Value="{x:Null}" />
</MultiTrigger.Conditions>
<Setter TargetName="BackgroundBorder" Property="Background" Value="{StaticResource ASiyah}" />
<Setter TargetName="BackgroundBorder" Property="BorderBrush" Value="{StaticResource ASiyah}" />
</MultiTrigger>
<Trigger Property="SortDirection" Value="Ascending">
<Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
<Setter TargetName="SortArrow" Property="RenderTransform">
<Setter.Value>
<RotateTransform Angle="180" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="SortDirection" Value="Descending">
<Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger Property="DisplayIndex" Value="0">
<Setter Property="Visibility" Value="Collapsed" TargetName="PART_LeftHeaderGripper"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="LightGray" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<EventSetter Event="MouseLeftButtonUp" Handler="InnerGridRowClick"/>
</Style>
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Kod" Binding="{Binding Kod}" Width="400" />
<DataGridTextColumn Header="Alt Secenakler" Binding="{Binding Alt_Secenakler}" Width="500" />
</DataGrid.Columns>
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"/>
</DataGrid.Resources>
</DataGrid>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
在上面的代码中,您可以看到 dataGridParent 是父数据网格,innerGrid 是内部 DataGrid。现在我的视图模型中有两个可观察的集合 1.GuestHostTotalList(是我的父 DataGrid 的 itemsource)和 2.SubGridItemList(用作 ItemSource我的 innerDataGrid)。但我看到内部网格没有填充数据。任何人都可以帮助我。在此先感谢。