I am using a scrollviewer control around my stack panel which contains an ItemsControl. When there are many items in the ItemsControl it is suppose to scroll but for some reason it just cuts of the items. Here is the code:
<StackPanel>
<ScrollViewer CanContentScroll="True" VerticalScrollBarVisibility="Visible">
<ItemsControl Name="icEvents" Width="Auto" Height="100" Background="AliceBlue"
ItemsSource="{Binding Path=EventSources}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="Source:"/>
<TextBlock Text="{Binding Path=Source}" />
<TextBlock Text="Original Source:"/>
<TextBlock Text="{Binding Path=OriginalSource}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</StackPanel>
Try a grid around your
ScrollViwerinstead of theStackPanel. I thinkStackPanelwill provide as much height as the internal content wants, so here theScrollviwerdoesn’t work properly since its height is not get restricted by its parent control.You can understand the issue from the example below.
Above code is similar to yours and it doesn’t give you scrollbars. But see the below code in which I changed only the
StackPanelto aGrid(Any panel which respects the size of its children based on panels size but stackpanel doesn’t)UPDATE : But if you really need to use
StackPanelthen you might need to set the size for yourScrollViwerto get the Content scroll