How to add ScrollBar to StackPanel in Silverlight?

I have a Grid , 3 on 3 (3 RowDefinitions and 3 ColumnDefinitions). I want some content (a StackPanel ) in one of these grid cells to scroll. I am sure that this is possible, but I cannot figure out how to do it. I tried adding the ScrollViewers and ScrollBar elements to the grid cell that I want to scroll, but this usually results in a scroll for the entire page.

Edit: My problem is more specific, as I can scroll through the StackPanel text. Example if I have a problem:

 <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> 
+4
source share
1 answer

StackPanel considers its contents to have infinite space. To scroll the stack panel, you will need to set a height limit on something - the parent of the panel stack grid, most likely.

+3
source

Source: https://habr.com/ru/post/1307677/


All Articles