Scrollviewer Problem wpf

I am displaying images inside the listbox. i have placed this listbox inside the scrollviewer. I am using two repeat button to move the listbox items. I am binding the listbox using datacontext.

Problem:

If i move the images using the button and click on the image in the lisbox it moves to the initial position.

Code:

   <RepeatButton Click="rbtnLeft_Click" Name="rbtnLeft" Width="30" Height="30">
                <Image Source="Images/GeneralImages/search_right_arrow.jpg"></Image>
            </RepeatButton>
            <Grid  x:Name="grid"  Width="666" HorizontalAlignment="Left">
                <ScrollViewer Grid.Row="1" Name="svGame"
                VerticalScrollBarVisibility="Hidden" 
                HorizontalScrollBarVisibility="Hidden"  >
                    <ListBox ClipToBounds="True" Name="lbGameImage" Width="Auto" SelectionChanged="lbGameImage_SelectionChanged" ItemsSource="{Binding}"   ItemsPanel="{DynamicResource iptListBox}" ItemContainerStyle="{DynamicResource ListBoxItemStyle}"
              ScrollViewer.VerticalScrollBarVisibility="Hidden" 
              ScrollViewer.HorizontalScrollBarVisibility="Hidden"/>
                </ScrollViewer>                                       
            </Grid>
            <RepeatButton Click="rbtnRight_Click" Name="rbtnRight" Width="30" Height="30">
                <Image Source="Images/GeneralImages/search_left_arrow.jpg"></Image>
            </RepeatButton>

c# Code:

private void rbtnLeft_Click(object sender, RoutedEventArgs e)
    {
        svGame.ScrollToHorizontalOffset(svGame.HorizontalOffset + 5);
    }

    private void rbtnRight_Click(object sender, RoutedEventArgs e)
    {
        svGame.ScrollToHorizontalOffset(svGame.HorizontalOffset - 5);
    }

Answers


The problem is that the ListBox thinks it owns the ScrollViewer, so whenever the selection changes it sets the offset back to what it wants. Set ScrollViewer.CanContentScroll="False" in the ListBox to prevent this.


You need to turn off the internal ScrollViewer inside the ListBox. You could do it by re-templating lbGameImage to remove the ScrollViewer completely but the quicker way (which it looks like you tried to do) is to set both of the ScrollBarVisibility settings on lbGameImage to "Disabled". Hidden means that they're still active and scrolling the content, you just can't see them.


Need Your Help

Merge pdf files with PDFBox using CLI

java cmd command-line-interface pdfbox

I found PDFBox by Apache but what do I for example write in the cmd?

Create customized zip including system.img, boot.img etc for Android customized ROM

rom cyanogenmod

I downloaded AOSP source code and built it as instructed in its official site.