0
votes

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>
1
'Does not work'? Can you be any more helpful? - LordWilmore
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

1 Answers

2
votes

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.