FlowLayoutPanel 的 WPF 等效项是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2599424/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 21:39:21  来源:igfitidea点击:

What is the WPF equivalent for the FlowLayoutPanel?

wpflayoutwpf-controlsflowlayoutpanel

提问by Sargola

I am working on a WPF application (a one note clone which is called "note your life") where you can dynamically assign Tags to an entry (just as in virtually any web 2.0 app these days). for this I had in my windows forms prototype a FlowLayoutPanel that did the job very well. I want to have the tags float to the next line if there isn't enough space and get a scrollbar if needed.

我正在开发一个 WPF 应用程序(一个称为“note your life”的单条笔记克隆),您可以在其中动态地将标签分配给一个条目(就像现在几乎所有的 web 2.0 应用程序一样)。为此,我在我的 Windows 窗体原型中有一个 FlowLayoutPanel,它很好地完成了这项工作。如果没有足够的空间,我想让标签浮动到下一行,并在需要时获取滚动条。

How can this be achieved with WPF? I played around with

如何使用 WPF 实现这一点?我玩过

<StackPanel Orientation="Horizontal" FlowDirection="LeftToRight" ...>

but this doesn't move the elements in the next line if needed.

但如果需要,这不会移动下一行中的元素。

回答by n535

Maybe Wrap panelwill help.

也许Wrap 面板会有所帮助。

<WrapPanel Orientation="Horizontal">
    <Button Margin="3">Button 1</Button>
    <Button Margin="3">Button 2</Button>
    <Button Margin="3">Button 3</Button>
    <Button Margin="3">Button 4</Button>
    <Button Margin="3">Button 5</Button>
</WrapPanel>

回答by Simon P Stevens

The WrapPanelhas similar behaviour to the old WinForms FlowLayoutPanel.

WrapPanel有类似的行为旧的WinForms FlowLayoutPanel的。