gpt4 book ai didi

c# - 使用堆栈面板 - 垂直 + 水平

转载 作者:行者123 更新时间:2023-11-30 22:09:36 25 4
gpt4 key购买 nike

堆栈面板可以垂直增长还是水平增长?

例如,

如果有 3 个堆栈面板项,那么,

项目 1

项目 2

项目 3

如果有 5 个堆栈面板项 那么,

项目 1 项目 4

项目 2 项目 5

项目 3

(最多在一行中,最多可以有n项,超过则开始新的一行)

还有一件事:我正在运行时(代码隐藏)创建堆栈面板项!

this.itemsPanel.Children.Add(item1);
this.itemsPanel.Children.Add(item2);
this.itemsPanel.Children.Add(item3);
this.itemsPanel.Children.Add(item5);

最佳答案

您想要一个带有 WrapPanel 的 ListBox,但您可能希望您的对象具有相同的大小、宽度和高度,这将等于您的最宽和最高的对象,这就是我们使用带有 IsSharedSizeScope 和 WrapPanel 的网格的原因。

<ListBox Name="ButtonList" 
HorizontalContentAlignment="Stretch"
BorderThickness="0"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
Padding="0"
Background="Transparent"
Margin="0"
Grid.IsSharedSizeScope="True"
>


<ListBox.ItemsPanel>
<ItemsPanelTemplate >
<WrapPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<!-- you need the grid, otherwise buttons are different heights depending on the control -->
<Grid.RowDefinitions>
<RowDefinition SharedSizeGroup="row1"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="col1"/>
</Grid.ColumnDefinitions>
<!-- put some control here -->

</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

关于c# - 使用堆栈面板 - 垂直 + 水平,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21434846/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com