簡體   English   中英

使用水平StackPanel作為ItemsPanel滾動ItemsControl

[英]Scrolling in a ItemsControl while using a horizontal StackPanel as the ItemsPanel

我有一個ItemsControl ,我已經構建了我正在其中顯示的項目( views:DisplayGroupView ),它們將水平擴展以顯示所有內容而不是垂直(僅使用可用高度)

我已經改變了我ItemsPanel中的ItemsControl使用StackPanelOrientation="Horizontal"

布局明智它是完美的,但無論我做什么我都不能讓它水平滾動所以我可以看到一切。

這是ItemsControl的XAML:

    <ItemsControl ItemsSource="{Binding DisplayGroups}" Grid.Row="1" Margin="120,20,120,20" VerticalContentAlignment="Stretch">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate >
                <StackPanel Orientation="Horizontal" ScrollViewer.HorizontalScrollMode="Enabled" ScrollViewer.HorizontalScrollBarVisibility="Visible"/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>

        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <views:DisplayGroupView Margin="0,0,20,0" DataContext="{Binding}" VerticalAlignment="Stretch"></views:DisplayGroupView>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>

這樣可以解決所有問題,但不會滾動。 我也嘗試更改ItemsControls模板以包含一個scrollviewer,但這只是垂直堆疊的東西:

            <ItemsControl.Template>
                <ControlTemplate>
                    <ScrollViewer x:Name="ScrollViewer" Padding="{TemplateBinding Padding}" VerticalContentAlignment="Stretch" ScrollViewer.HorizontalScrollMode="Enabled" ScrollViewer.VerticalScrollMode="Disabled">
                        <ItemsPresenter VerticalAlignment="Stretch"/>
                    </ScrollViewer>
                </ControlTemplate>
            </ItemsControl.Template>

如何在能夠滾動的同時獲得水平布局?

如果你把它從ItemsControl拉出來並自己嵌入它,出於某種原因,這通常會起到解決方法的作用,如:

<ScrollViewer VerticalScrollBarVisibilty="Disabled" HorizontalScrollBarVisibility="Auto">
  <ItemsControl/>
</ScrollViewer>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM