2013-08-06 112 views
8

如何添加一个滚动条让我滚动浏览水平显示的项目?水平滚动ItemsControl

<ItemsControl ItemsSource="{Binding Data, ElementName=myWindows}"> 
     <ItemsControl.ItemsPanel> 
      <ItemsPanelTemplate> 
       <VirtualizingStackPanel Orientation="Horizontal"> 
       </VirtualizingStackPanel> 
      </ItemsPanelTemplate> 
     </ItemsControl.ItemsPanel> 
     <ItemsControl.ItemContainerStyle> 
      <Style TargetType="FrameworkElement" > 
       <Setter Property="Margin" Value="10,0,10,0"></Setter> 
      </Style> 
     </ItemsControl.ItemContainerStyle> 
    </ItemsControl> 

回答

16
<ItemsControl ItemsSource="{Binding Data, ElementName=myWindows}"> 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <VirtualizingStackPanel Orientation="Horizontal"/> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 

    <!-- Add this Template --> 
    <ItemsControl.Template> 
     <ControlTemplate TargetType="ItemsControl"> 
      <ScrollViewer HorizontalScrollBarVisibility="Visible"> 
       <ItemsPresenter/> 
      </ScrollViewer> 
     </ControlTemplate> 
    </ItemsControl.Template> 

    <!-- ... Etc ... --> 
</ItemsControl> 
+2

这是神奇的。谢谢 –