Search code examples
xamlwindows-8windows-store-apps

Row of data on grid now showing


I am working on rendering a table with selectable rows. Ultimately the data coming in will be data-bound from a database but right now I'm just trying to get a row to show. Here is what I have:

                <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>

The header's are being rendered but the 1st row which should just have numerical values is not showing:

enter image description here

What am I doing wrong? Why isn't the row of data showing?


Solution

  • As I stated in my comment, you have not added any items to the listbox so the dataTemplate will not show.

    For testing you can add items after the ItemTemplate:

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