2010-07-06 100 views
2

我在列表框中顯示圖像。我已經將這個列表框放置在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); 
    } 

回答

5

的問題是,列表框認爲它擁有的ScrollViewer,所以只要選擇改變其設置偏移回它想要的東西。在列表框中設置ScrollViewer.CanContentScroll="False"以防止出現這種情況。

+0

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

1

您需要關閉ListBox內部的ScrollViewer。你可以通過重新模板化lbGameImage來完全移除ScrollViewer,但更快的方式(它看起來像你試圖做的)是將lbGameImage上的ScrollBarVisibility設置都設置爲「Disabled」。隱藏意味着他們仍然活躍並滾動內容,但您無法看到它們。

+0

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