【问题标题】:Display ListBox inside of RadGrid while using DataBinding使用 DataBinding 时在 RadGrid 内显示 ListBox
【发布时间】:2017-06-30 12:17:52
【问题描述】:

我创建了一个内容应用程序,它显示代表不同情况的曲目列表(目前)。它们每个都有一个目标按钮、案例编号、案例类型和日期。我正在使用 telerik:radgridview 来实现这一点,并且每一行都是可点击的。展开该行时,您会看到有关情况的更多信息。一个部分称为“响应资产”。在本节中,我想显示一个 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 中单击行。

【问题讨论】:

    标签: c# wpf xaml telerik


    【解决方案1】:

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

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

    【讨论】:

    • 像魅力一样工作!谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-30
    • 1970-01-01
    相关资源
    最近更新 更多