views:

807

answers:

2

I have a grid, 3 by 3 (3 rowdefinitions and 3 columndefinitions). I want some content (a StackPanel) in one of those grid cells to scroll. I'm fairly sure this is possible but I cannot figure out how. I've tried adding ScrollViewers and Scrollbar controls to the grid cell I want to scroll, but this usually ends up creating scrolling for the entire page.

Edit: My issue is more specificlly how I can get scrolling over a StackPanel. An example if the issue I am having is here:

<Grid x:Name="LayoutRoot">
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
    </Grid.RowDefinitions>

    <Grid>
        <TextBlock FontSize="16">1,1</TextBlock>
    </Grid>
    <Grid Grid.Column="1">
        <TextBlock FontSize="16">1,2</TextBlock>
    </Grid>
    <Grid Grid.Row="1">
        <TextBlock FontSize="16">2,1</TextBlock>
    </Grid>
    <Grid Grid.Column="1" Grid.Row="1">
        <StackPanel>
            <TextBlock>Title</TextBlock>
            <Grid>
                <ScrollViewer>
                    <StackPanel>
                        <TextBlock FontSize="32">2,2</TextBlock>
                        <TextBlock FontSize="32">2,2</TextBlock>
                        <TextBlock FontSize="32">2,2</TextBlock>
                        <TextBlock FontSize="32">2,2</TextBlock>
                        <TextBlock FontSize="32">2,2</TextBlock>
                        <TextBlock FontSize="32">2,2</TextBlock>
                        <TextBlock FontSize="32">2,2</TextBlock>
                        <TextBlock FontSize="32">2,2</TextBlock>
                        <TextBlock FontSize="32">2,2</TextBlock>
                        <TextBlock FontSize="32">2,2</TextBlock>
                        <TextBlock FontSize="32">2,2</TextBlock>
                        <TextBlock FontSize="32">2,2</TextBlock>
                        <TextBlock FontSize="32">2,2</TextBlock>
                        <TextBlock FontSize="32">2,2</TextBlock>
                    </StackPanel>
                </ScrollViewer>
            </Grid>
        </StackPanel>
    </Grid>
</Grid>
A: 

StackPanel treats its content has having infinite space. To scroll the stackpanel, you're going to have to put a height constraint on something - the grid parent of the stackpanel, most likely.

dthorpe
is there a way to set the height of the stackpanel so that it dynamically changes along with its parent grid?
programatique
If you set the height of the stackpanel, then the controls within it won't be displayed. You need to let the stackpanel size to fit the controls within it, and then scroll the stackpanel within the display viewport. Set the height of the grid that is the parent of the innermost stackpanel. The scrollviewer will then scroll the larger stackpanel within the smaller grid viewport.
dthorpe
A: 

There is a scroll effect like iphone using stackpanel and canvas

http://www.shinedraw.com/text-effect/silverlight-3-and-flash-iphone-dragging-effect/

Ema_H