使用 DataBinding 时在 RadGrid 内部显示 ListBox

Display ListBox inside of RadGrid while using DataBinding

我创建了一个内容应用程序,它显示了代表不同情况的曲目列表(目前)。它们每个都有一个目标按钮、案例编号、案例类型和日期。我正在使用 telerik:radgridview 来实现这一点,每一行都是可点击的。展开该行时,您会看到有关该情况的更多信息。一个部分称为 'Responding Assets'。在本节中,我想显示一个 ListBox 或任何我可以用来再次显示相同轨道的东西。这只是为了测试目的,稍后我会给你一组特定的数据,但我无法在此处显示任何内容。我不知道尝试在 radgrid 中显示另一个列表是否有问题或什么?知道为什么这不起作用吗?

.xaml代码

<telerik:RadGridView.RowDetailsTemplate>
    <DataTemplate>
        <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="Auto" Background="#303134" Name="RowDetails">
            <Grid Margin="10 10">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="1*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <!--SUMMARY-->
                <Grid Margin="10 10" Grid.ColumnSpan="2">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <TextBlock Text="SUMMARY" FontSize="14" FontFamily="Segoe UI Bold"  Foreground="White" Margin="4 0 0 5" />
                    <Rectangle Height="1" Fill="#A6A6A6" Grid.Row="1" VerticalAlignment="Center" Margin="2 0 2 10" Stretch="Fill" Grid.ColumnSpan="2" />
                    <TextBlock Text="Address: " FontSize="12" FontFamily="Segoe UI Bold"  Foreground="#A6A6A6" Margin="4 2" Grid.Row="2" />
                    <TextBlock Text="1501 Main Street Columbia, SC" FontSize="12" FontFamily="Segoe UI"  Foreground="#A6A6A6" Margin="4 2" 
                                       Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left" />
                    <TextBlock Text="Subtype: " FontSize="12" FontFamily="Segoe UI Bold"  Foreground="#A6A6A6" Margin="4 2" Grid.Row="3" />
                    <TextBlock Text="Active Shooter on Foot" FontSize="12" FontFamily="Segoe UI"  Foreground="#A6A6A6" Margin="4 2" Grid.Row="3" 
                                       Grid.Column="1" HorizontalAlignment="Left"/>
                    <TextBlock Text="Dispatch Group: " FontSize="12" FontFamily="Segoe UI Bold"  Foreground="#A6A6A6" Margin="4 2" Grid.Row="4"/>
                    <TextBlock Text="District 22" FontSize="12" FontFamily="Segoe UI"  Foreground="#A6A6A6" Margin="4 2" Grid.Row="4" Grid.Column="1" 
                                       HorizontalAlignment="Left"/>
                </Grid>

                <!--COMMENTS-->
                <Grid Margin="10 10" Grid.Row="1" Grid.ColumnSpan="2">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="1*" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <TextBlock Text="COMMENTS" FontSize="14" FontFamily="Segoe UI Bold"  Foreground="White" Margin="4 10 0 5" />
                    <Rectangle Height="1" Fill="#A6A6A6" Grid.Row="1" VerticalAlignment="Center" Margin="2 0 2 10" Stretch="Fill" />
                    <TextBlock Text="Event Comments" FontSize="12" FontFamily="Segoe UI Bold"  Foreground="#A6A6A6" Margin="4 6" Grid.Row="2"/>
                    <Border Grid.Row="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="100" BorderBrush="#535354">
                        <TextBox Grid.Row="3" Name="EventComments" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" TextAlignment="Left"
                                     Margin="4 0 10 10" TextWrapping="Wrap" Text="Comments from CAD system here" IsReadOnly="True" Height="100" Background="#3F4145" 
                                     BorderThickness="0" Foreground="#A6A6A6" />
                    </Border>
                    <TextBlock Text="Location Comments" FontSize="12" FontFamily="Segoe UI Bold"  Foreground="#A6A6A6" Margin="4 6" Grid.Row="4"/>
                    <Border Grid.Row="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="100" BorderBrush="#535354">
                        <TextBox Grid.Row="5" Name="LocationComments" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" TextAlignment="Left"
                                     Margin="4 0 10 10" TextWrapping="Wrap" IsReadOnly="True" Height="100" Background="#3F4145" 
                                     BorderThickness="0" Foreground="#A6A6A6" />
                    </Border>
                </Grid>

                <!--RESPONDING ASSETS-->
                <Grid Margin="10 10" Grid.Row="2" Grid.ColumnSpan="2">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="1*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="300" />
                    </Grid.RowDefinitions>
                    <TextBlock Text="RESPONDING ASSETS" FontSize="14" FontFamily="Segoe UI Bold"  Foreground="White" Margin="4 10 0 5" />
                    <Rectangle Height="1" Fill="#A6A6A6" Grid.Row="1" VerticalAlignment="Center" Margin="2 0 2 10" Stretch="Fill" />

                    <!--ENTITY LIST-->

                    <Grid Grid.Row="2">
                        <ListBox ItemsSource="{Binding FilteredTrackList}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0 5 0 10">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Grid Margin="0 2">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="100" />
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Text="{Binding TrackName.Value}" />
                                        <TextBlock Text="{Binding DateCreated}" />
                                    </Grid>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </Grid>

                </Grid>
            </Grid>
        </StackPanel>
    </DataTemplate>
</telerik:RadGridView.RowDetailsTemplate>

我没有提供我如何获得 FilteredTrackList 的代码,因为这显然有效,否则我不会在 radgrid 中点击行。

ListBoxDataContext 是一个单独的 Entity 对象。如果你想绑定到与父 RadGridView 绑定到的相同的 FilteredTrackList,你可以使用 {RelativeSource}:

<ListBox ItemsSource="{Binding DataContext.FilteredTrackList, RelativeSource={RelativeSource AncestorType=telerik:RadGridView}}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0 5 0 10">