横向滚动的ItemsControl

10

我该如何添加一个可以让我水平滚动显示的项目的滚动条?

   <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>
1个回答

27
<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>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接