c# - How can I force ListBoxItems to display inline in XAML
问题描述
<ListBox Background="Black" ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBoxItem Background="White" Width="150" Height="200" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5">Item0</ListBoxItem>
<ListBoxItem Background="White" Width="150" Height="200" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5">Item1</ListBoxItem>
<ListBoxItem Background="White" Width="150" Height="200" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5">Item2</ListBoxItem>
<ListBoxItem Background="White" Width="150" Height="200" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5">Item3</ListBoxItem>
<ListBoxItem Background="White" Width="150" Height="200" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5">Item4</ListBoxItem>
<ListBoxItem Background="White" Width="150" Height="200" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5">Item5</ListBoxItem>
<ListBoxItem Background="White" Width="150" Height="200" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5">Item6</ListBoxItem>
<ListBoxItem Background="White" Width="150" Height="200" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5">Item7</ListBoxItem>
</ListBox>
This code above produces this Image below.
But I want to create something like this image below. Where the box breaks down to the next line at the end of it's parent control. And I want to achieve this using XAML (and C# if required)
解决方案
只需将您的 ItemsPanelTemplate 更改为
<ItemsPanelTemplate>
<WrapPanel MaxWidth="800" Orientation="Horizontal"/>
</ItemsPanelTemplate>
推荐阅读
- python-3.x - python调度多个函数
- discord - 使用 discord.js 访问 API 时出错,但仅在嵌入时出错?
- javascript - firebase 实时数据库读取缺少数据的 json
- python - 为什么 MultiOutputRegressor 方法的平均绝对误差 (MAE) 显示一个值而不是三个?
- pandas - Group by 返回空数据框并且没有错误
- laravel - laravel & vue.JS:app.js 中的“组件”、“导入”和“使用”
- python - 在python中读取当前目录中所有文件的内容
- javascript - Instagram JSON 响应重定向到登录 [Discord JS 和 Heroku]
- elasticsearch - 如何使用命名空间和 SVC 在 Kubernetes 集群 pod 之间进行通信
- python - Tkinter create_window,居中对齐