tags:

views:

398

answers:

4

Someone help me out pls.

I set a wrapPanel in a listbox itemPanelTemplate, 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.

Is 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>
A: 

Hi,

I think i may be able to help, although i'm not exactly sure what you are trying to achieve. Can you be more specific; are you trying to get each ListBoxItem to have scrolling ability - for its content?

Since you can't add a ScrollViewer to the ItemPanelTemplate, have you considered adding one to the individual ListBoxItems:

Example:

<ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
                <ScrollViewer>
                    <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/> 
                </ScrollViewer>
            </ListBoxItem>

For more wpf/xaml help i found this site was quite good: www.YourCodeFactory.com

codeB10
Thank codeB10.I want to achieve the listbox scrolling ability that scroll image item by item. That mean I can scroll the listboxitem row by row instead of smoothly by pixel.you can try to mark up the "<ListBox.ItemsPanel>" block in above code and try the scroll by item.It's strange that listbox is not scrolling by item when I add the wrappanel block.
Jayho
Hi - would really like to help. But i'm still not sure what you are trying to achieve.If you want to scroll by row - a wrappanel is not necessary therefore. But if you want to populate each item with an undefined number of images, i think the setup of the listview is wrong. Either way, please clarify if you still require a solution. Also, not sure what you mean by smothly by pixel, what exactly are you referring to there?
codeB10
A: 

Thank codeB10.

I want to achieve the listbox scrolling ability that scroll image item by item. That mean I can scroll the listboxitem row by row instead of smoothly by pixel.

you can try to mark up the "ListBox.ItemsPanel" block in above code and try the scroll by item.

It's strange that listbox is not scrolling by item when I add the wrappanel block.

Jayho
A: 

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.

Albert Oldfield
A: 

Albert, Can you please provide sample code if you have any.. Which methods of IScrollInfo should I implement?

Vin