Someone help me out, please.
I set a WrapPanel in a ListBox ItemsPanelTemplate. Also, I already set the ScrollViewer.CanContentScroll="True"
.
But why the listbox items are not scrolling up/down by ITEM one by one? The scroll style is still by PIXEL.
Can anyone help me?
<Grid>
<ListBox x:Name="testListbox" ScrollViewer.CanContentScroll="True">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Width="200" ScrollViewer.CanContentScroll="True"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
<Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
</ListBoxItem>
<ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
<Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
</ListBoxItem>
<ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
<Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
</ListBoxItem>
<ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
<Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
</ListBoxItem>
<ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
<Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
</ListBoxItem>
<ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
<Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
</ListBoxItem>
<ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
<Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
</ListBoxItem>
<ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
<Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
</ListBoxItem>
<ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
<Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
</ListBoxItem>
<ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
<Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
</ListBoxItem>
<ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
<Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
</ListBoxItem>
<ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
<Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
</ListBoxItem>
<ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
<Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
</ListBoxItem>
<ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
<Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
</ListBoxItem>
<ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
<Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
</ListBoxItem>
<ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
<Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
</ListBoxItem>
</ListBox>
</Grid>
Best Answer
The wrappanel was not designed with this feature (logical scrolling) in mind. You will need to create a new panel object deriving from the wrappanel class and then implement the IScrollInfo interface in order to achieve the results that you're looking for.