0

I'm quite new to WPF and I'm sure I'm missing something trivial. The scrollviewer does not work when the content of the stackpanel grows.

<ItemsControl>
                <TextBlock Margin="30,4,0,4" Text="Associated Data: None" Visibility="{Binding SelectedPBL.PBLData.Count, Converter={StaticResource VisibleIfZero}}"/>
                <ScrollViewer>
                    <StackPanel Margin="30,4,0,4" Orientation="Horizontal" Visibility="{Binding SelectedPBL, Converter={StaticResource CollapsedIfNull}}" ScrollViewer.VerticalScrollBarVisibility="Auto">
                        <TextBlock FontSize="12" Text="Associated Data:" Visibility="{Binding SelectedPBL.PBLData.Count, Converter={StaticResource CollapsedIfZero}}"/>
                        <ItemsControl FontSize="12" ItemsSource="{Binding SelectedPBL.PBLData}" >
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <WrapPanel Margin="20,0,20,0" Orientation="Horizontal">
                                        <TextBlock Margin="0,0,10,0" Text="{Binding Path=Key, StringFormat=({0})}"/>
                                        <TextBlock Text="{Binding Path=Value}"/>
                                    </WrapPanel>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                </StackPanel>
                </ScrollViewer>
            </ItemsControl>
anya
  • 27
  • 7
  • 1
    'Does not work'? Can you be any more helpful? – LordWilmore Sep 09 '16 at 14:06
  • Depends on where `ItemsControl` is located. Most probably `ScrollViewer` receives all the space it needs to it doesn't show scrollbars. Try settings some Height to ScrollViewer and see if it works. – icebat Sep 09 '16 at 14:10
  • 1
    Possible duplicate of [How can I get ScrollViewer to work inside a StackPanel?](http://stackoverflow.com/questions/802821/how-can-i-get-scrollviewer-to-work-inside-a-stackpanel?rq=1) – mechanic Sep 09 '16 at 14:20

1 Answers1

2

Try restricting the Height of your ItemsControl or ScrollViewer (e.g. add Height="200"). If the height is not restricted, the ScrollViewer will take as much room as it needs and will never see a reason to scroll.

Tim Oehler
  • 109
  • 3