滚动查看器问题wpf

滚动查看器问题wpf

问题描述:

我在列表框中显示图像。我已经将这个列表框放置在scrollviewer中。我正在使用两个重复按钮来移动列表框项目。我使用datacontext绑定列表框。滚动查看器问题wpf

问题:

如果我移动使用按钮图像,并点击它移动到初始位置的lisbox在图像上。

代码:

<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#代码:

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); 
    } 

的问题是,列表框认为它拥有的ScrollViewer,所以只要选择改变其设置偏移回它想要的东西。在列表框中设置ScrollViewer.CanContentScroll="False"以防止出现这种情况。

+0

非常感谢。 – Geeth 2010-07-07 04:25:33

您需要关闭ListBox内部的ScrollViewer。你可以通过重新模板化lbGameImage来完全移除ScrollViewer,但更快的方式(它看起来像你试图做的)是将lbGameImage上的ScrollBarVisibility设置都设置为“Disabled”。隐藏意味着他们仍然活跃并滚动内容,但您无法看到它们。

+0

非常感谢。 – Geeth 2010-07-07 04:27:13