c# - Stackpanel 中的水平方向,Stackpanel 宽度末尾的新行

标签 c# wpf xaml stackpanel

假设我们有一个水平方向且宽度为 100 像素的 Stackpanel。

在里面我制作了 11 个宽度为 10px 的方形 Canvas 绘图。

这意味着最后一个正方形将在 View 之外,因为它将扩展堆栈面板宽度 10 像素。所以我希望这个方 block 换行。

是否有控件可以做到这一点? 困难的部分是 Stackpanel 将是动态的,因此如果我调整 WPF 窗口的大小,Stackpanel 将为 50px,这将导致 2 条完整的方形线和第三 strip 有单个方形的线。

我希望这是有道理的。 我该怎么做?

谢谢,乔纳坦

最佳答案

在这种情况下,您需要包裹面板

    <WrapPanel  Width="100" Orientation="Horizontal">
        <Button   Width="10" Height="20"/>
        <Button   Width="10" Height="20"/>
        <Button   Width="10" Height="20"/>
        <Button   Width="10" Height="20"/>
        <Button   Width="10" Height="20"/>
        <Button   Width="10" Height="20"/>
        <Button   Width="10" Height="20"/>
        <Button   Width="10" Height="20"/>
        <Button   Width="10" Height="20"/>
        <Button   Width="10" Height="20"/>
        <Button   Width="10" Height="20"/>
    </WrapPanel>

关于c# - Stackpanel 中的水平方向,Stackpanel 宽度末尾的新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29259544/

相关文章:

c# - 使用 EF 查询的最佳方式

c# - 正确使用 Marshal.Copy

wpf - 获取控件的样式 {StaticResource {x :Type TextBlock}} in code behind

c# - 如何在WPF中 move 按钮

c# - 在 Windows 8 应用商店中使用 C# 选择控件时更改边框颜色

c# - 主数据管理 - 数据冗余

c# - 发送数据到 127.* : Unreachable Host

wpf - 在 WPF Frame 控件中关闭导航页面声音

c# - C#/WPF 中的选项卡式界面

c# - DropShadowPanel 和边框圆角半径