我有一個ItemsControl項目。我想要像圖片中那樣排列物品。如果有更多的元素,該空間應該有一個水平滾動條。我如何歸檔這個?滾動條ItemsControl垂直填充,然後水平滾動
相關代碼:
<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
<ScrollViewer PanningMode="Both" >
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
編輯: 我就是報道說,建議的解決方案沒有工作對不起,原來該項目的高度是在運行時動態改變,導致只有一個項目垂直的空間。
按預期這是行不通的。我更新了我的照片以澄清問題。 – Florian
將固定高度設置爲WrapPanel並將方向設置爲垂直並將高度和寬度固定爲ScrollViewer後,它不工作? – user1246682