我需要滚动扩展器及其位于窗口中的 stackpanel 对象
这是我的代码,我想知道如何完全卷起堆栈、扩展器和其中的对象,以将其下方的所有对象推入其中,以占用卷起上层堆栈和对象后留下的空间。我当前的代码如下:
<Grid>
<StackPanel Margin="8,8,0,0" VerticalAlignment="Top" Height="225">
<Expander Header="Expander">
<Grid Height="201">
<ListBox HorizontalAlignment="Left" Margin="103,63,0,38" Width="100">
<ListBoxItem Content="Brown"/>
<ListBoxItem Content="Red"/>
<ListBoxItem Content="Green"/>
<ListBoxItem Content="Yellow"/>
</ListBox>
</Grid>
</Expander>
</StackPanel>
<StackPanel Margin="0,0,0,8" VerticalAlignment="Bottom" Height="221">
<Expander Header="Expander">
<Grid Height="194">
<ListBox Margin="177,21,213,73">
<ListBoxItem Content="Gold"/>
<ListBoxItem Content="Silver"/>
<ListBoxItem Content="Platinum"/>
<ListBoxItem Content="Palladium"/>
</ListBox>
</Grid>
</Expander>
</StackPanel>
</Grid>
Here is the code I have and wondered how I could completely rollup the stack, expander and objects within it to push all objects below it to take up the space left after rolling up the upper stack and objects. My current code is below:
<Grid>
<StackPanel Margin="8,8,0,0" VerticalAlignment="Top" Height="225">
<Expander Header="Expander">
<Grid Height="201">
<ListBox HorizontalAlignment="Left" Margin="103,63,0,38" Width="100">
<ListBoxItem Content="Brown"/>
<ListBoxItem Content="Red"/>
<ListBoxItem Content="Green"/>
<ListBoxItem Content="Yellow"/>
</ListBox>
</Grid>
</Expander>
</StackPanel>
<StackPanel Margin="0,0,0,8" VerticalAlignment="Bottom" Height="221">
<Expander Header="Expander">
<Grid Height="194">
<ListBox Margin="177,21,213,73">
<ListBoxItem Content="Gold"/>
<ListBoxItem Content="Silver"/>
<ListBoxItem Content="Platinum"/>
<ListBoxItem Content="Palladium"/>
</ListBox>
</Grid>
</Expander>
</StackPanel>
</Grid>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解了您想要执行的操作,您可以使用网格中的星号大小来完成此操作。星形大小告诉网格使用所有剩余的可用大小(如果多行/列是星形大小,则按比例划分)。因此:
请注意 Grid.Row 附加属性。
现在,当您将第一个 StackPanel 的可见性设置为 Collapsed 时,它不占用任何高度。因此网格的第一行依次折叠到零高度。因此,网格的整个高度都专用于第二行,这意味着网格的整个高度都分配给第二个 StackPanel 及其内容。
这就是你所追求的结果吗?我可能误解了这个问题......如果是这样,请发表评论,我将更新或删除。
If I've understood correctly what you want to do, you can do this using star sizing in your Grid. Star sizing tells the Grid to use all remaining available size (divvied up in proportion if multiple rows/columns are star-sized). Thus:
Note the Grid.Row attached properties.
Now when you make set the first StackPanel's visibility to Collapsed, it takes up no height. So in turn the first row of the Grid collapses to zero heigh. So the entire height of the grid is devoted to the second row, which means that the entire height of the grid is given over to the second StackPanel and its contents.
Is this the outcome you're after? I may have misunderstood the question... if so please leave a comment and I will update or delete.