2

I'm building an app with Silverlight for WP7. I have a ListBox in a PivotItem with some content. I would like the ListBox to scroll to display all content. Unfortunately, the user can't scroll down all the way - the last items are cut off.

Here is the XAML:

    <controls:Pivot Title="SECTIONS" x:Name="pivotControl" ItemsSource="{Binding SectionViewModels}">
        <controls:Pivot.HeaderTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding DisplayName}" />
            </DataTemplate>
        </controls:Pivot.HeaderTemplate>
        <controls:Pivot.ItemTemplate>
            <DataTemplate>
                <StackPanel>
                    <TextBlock Style="{StaticResource disabledText}" Visibility="{Binding NoStoryContent}">
                        Content could not be downloaded from MySite.com. Do you have a network connection?
                    </TextBlock>

                    <!-- fake data to demonstrate -->
                    <ListBox FontSize="100">
                        <ListBoxItem Content="A" />
                        <ListBoxItem Content="B" />
                        <ListBoxItem Content="C" />
                        <ListBoxItem Content="D" />
                        <ListBoxItem Content="E" />
                        <!-- the user can scroll no lower than the top half of the 'F' -->
                        <ListBoxItem Content="F" />
                        <ListBoxItem Content="G" />
                    </ListBox>

                </StackPanel>
            </DataTemplate>
        </controls:Pivot.ItemTemplate>
    </controls:Pivot>

Aside from the scrolling issue, everything else looks/works fine with this control.

What could I be doing wrong?

Update: It works fine if I explicitly specify the height.

Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
  • Have you looked at scrollviewer(http://msdn.microsoft.com/en-us/library/system.windows.controls.scrollviewer.aspx) and this question(http://stackoverflow.com/questions/472796/how-can-i-get-a-vertical-scrollbar-in-my-listbox) – Eugene Jan 07 '11 at 22:53

2 Answers2

0

I haven't used the pivot control, so I'm not sure if this is what you need, but I would try first the ScrollViewer containing the Listbox.

Dario
  • 149
  • 2
0

The problem is you are using a StackPanel when you should be using a Grid.

        <controls:Pivot.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <TextBlock Style="{StaticResource disabledText}" Visibility="{Binding NoStoryContent}">
                        Content could not be downloaded from MySite.com. Do you have a network connection?
                    </TextBlock>

                    <!-- fake data to demonstrate -->
                    <ListBox FontSize="100">
                        <ListBoxItem Content="A" />
                        <ListBoxItem Content="B" />
                        <ListBoxItem Content="C" />
                        <ListBoxItem Content="D" />
                        <ListBoxItem Content="E" />
                        <!-- the user can scroll no lower than the top half of the 'F' -->
                        <ListBoxItem Content="F" />
                        <ListBoxItem Content="G" />
                    </ListBox>

                </Grid>
            </DataTemplate>
        </controls:Pivot.ItemTemplate>

Now it scrolls as expected.

AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
  • Why does the `Grid` behave differently than the `StackPanel` in this regard? – Nick Heiner Jan 08 '11 at 19:38
  • A `StackPanel` pays no attention to available size in the direction of its orientation it will grow to however big its contents wants to be. When the ListBox asks for prefered height the `StackPanel` will just give what it asks for. The StackPanel doesn't care that it's bottom is not visible and therefore the bottom of the ListBox is not visible. A `Grid` on the other hand will do its best to keeps its contents within the size it has been given by its container. – AnthonyWJones Jan 08 '11 at 21:09