簡體   English   中英

滾動條ItemsControl垂直填充,然后水平滾動

[英]Scrollbar ItemsControl fill vertically and then scroll horizontal

我有一個帶項目的ItemsControl。 我希望像照片中那樣訂購物品。 如果有更多元素,那個空格,應該有一個水平滾動條。 我該如何存檔?

在此輸入圖像描述 相關代碼:

 <ItemsControl.Template>
    <ControlTemplate TargetType="ItemsControl">
      <ScrollViewer PanningMode="Both" >
        <ItemsPresenter />
       </ScrollViewer>
      </ControlTemplate>
  </ItemsControl.Template>
  <ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
      <WrapPanel />
    </ItemsPanelTemplate>
  </ItemsControl.ItemsPanel>

編輯:很抱歉,報告建議的解決方案不起作用,結果是項目的高度在運行時動態變化,導致只有一個項目的空間垂直。

會不會像這樣的工作?

<ItemsControl.Template>
    <ControlTemplate TargetType="ItemsControl">
      <ScrollViewer HorizontalScrollBarVisibility="Auto"
           VerticalScrollBarVisibility="Disabled" >

如果這不起作用,試試這個

<ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
      <WrapPanel Height="{Binding RelativeSource={RelativeSource 
          Mode=FindAncestor, AncestorType={x:Type ScrollViewer}}, 
          Path=ActualHeight}" />

編輯

別忘了讓你的WrapPanel Orientation="Vertical"

您的問題的示例代碼

<ItemsControl.Template>
                <ControlTemplate>
                <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden" Height="100" Width="200">
                        <ItemsPresenter />
                    </ScrollViewer>
                </ControlTemplate>
            </ItemsControl.Template>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel Orientation="Vertical" Height="100"/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>

希望這是你要找的東西!

<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled" >
    <ItemsControl>
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel Orientation="Vertical" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>
</ScrollViewer>

使用ListBox簡單:

<ListBox ScrollViewer.VerticalScrollBarVisibility="Disabled" >
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel Orientation="Vertical"  />
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
</ListBox>

暫無
暫無

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

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