网格上的数据行现在显示

Row of data on grid now showing

我正在渲染带有选择table 行的table。最终传入的数据将是来自数据库的 data-bound,但现在我只是想显示一行。这是我拥有的:

                <Grid Background="WhiteSmoke">
                    <StackPanel>
                        <Grid Width="900">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="100" />
                                <ColumnDefinition Width="200" />
                                <ColumnDefinition Width="200" />
                                <ColumnDefinition Width="100" />
                                <ColumnDefinition Width="100" />
                                <ColumnDefinition Width="100" />
                                <ColumnDefinition Width="100" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <Grid.Resources>
                                <Style TargetType="Border">
                                    <Setter Property="BorderBrush" Value="Black" />
                                    <Setter Property="BorderThickness" Value="2" />
                                    <Setter Property="Background" Value="White" />
                                    <Setter Property="Padding" Value="5" />
                                </Style>
                                <Style TargetType="TextBlock">
                                    <Setter Property="Foreground" Value="Black" />
                                </Style>
                            </Grid.Resources>
                            <Border Grid.Column="0" Grid.Row="1">
                                <TextBlock Text="Status" />
                            </Border>
                            <Border Grid.Column="1" Grid.Row="1">
                                <TextBlock Text="Work Package" />
                            </Border>
                            <Border Grid.Column="2" Grid.Row="1">
                                <TextBlock Text="Description" />
                            </Border>
                            <Border Grid.Column="3" Grid.Row="1">
                                <TextBlock Text="Foreman" />
                            </Border>
                            <Border Grid.Column="4" Grid.Row="1">
                                <TextBlock Text="Field Issue" />
                            </Border>
                            <Border Grid.Column="5" Grid.Row="1">
                                <TextBlock Text="Start Date" />
                            </Border>
                            <Border Grid.Column="6" Grid.Row="1">
                                <TextBlock Text="Finish Date" />
                            </Border>
                        </Grid>
                        <ListBox >
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Grid Width="900">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="100" />
                                            <ColumnDefinition Width="200" />
                                            <ColumnDefinition Width="200" />
                                            <ColumnDefinition Width="100" />
                                            <ColumnDefinition Width="100" />
                                            <ColumnDefinition Width="100" />
                                            <ColumnDefinition Width="100" />
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition />
                                            <RowDefinition />
                                        </Grid.RowDefinitions>
                                        <Grid.Resources>
                                            <Style TargetType="Border">
                                                <Setter Property="BorderBrush" Value="Black" />
                                                <Setter Property="BorderThickness" Value="2" />
                                                <Setter Property="Background" Value="White" />
                                                <Setter Property="Padding" Value="5" />
                                            </Style>
                                            <Style TargetType="TextBlock">
                                                <Setter Property="Foreground" Value="Black" />
                                            </Style>
                                        </Grid.Resources>
                                        <Border Grid.Column="0" Grid.Row="1">
                                            <TextBlock Text="1" />
                                        </Border>
                                        <Border Grid.Column="1" Grid.Row="1">
                                            <TextBlock Text="2" />
                                        </Border>
                                        <Border Grid.Column="2" Grid.Row="1">
                                            <TextBlock Text="3" />
                                        </Border>
                                        <Border Grid.Column="3" Grid.Row="1">
                                            <TextBlock Text="4" />
                                        </Border>
                                        <Border Grid.Column="4" Grid.Row="1">
                                            <TextBlock Text="5" />
                                        </Border>
                                        <Border Grid.Column="5" Grid.Row="1">
                                            <TextBlock Text="6" />
                                        </Border>
                                        <Border Grid.Column="6" Grid.Row="1">
                                            <TextBlock Text="7" />
                                        </Border>
                                    </Grid>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </StackPanel>
                </Grid>

header 正在呈现,但应该只有数值的第一行没有显示:

我做错了什么?为什么数据行没有显示?

正如我在评论中所述,您尚未向列表框中添加任何项目,因此不会显示数据模板。

为了测试,您可以在 ItemTemplate 之后添加项目:

    </ListBox.ItemTemplate>
    <ListBoxItem>Item 1</ListBoxItem>
    <ListBoxItem>Item 2</ListBoxItem>
</ListBox>