WPF 可扩展 StackPanel(或其他)

WPF expandable StackPanel (or something else)

我需要一个可扩展的内容控件,例如 Chrome 的书签栏。我无法解决的事情是右侧带有 >> 内容的按钮。仅当 window 宽度不足以显示所有书签时才可见。

我认为 StackPanel 最适合这个(因为这样它的方向可能会改变),但我不知道如何自动向它添加 >> 按钮以及不可见按钮的内容到其上下文菜单。
另一件事我想过用一种菜单来做这件事,但我真的没有什么好主意...

提前致谢,万一有人有。

Toolbar control has the overflow functionality built in. Specifically, the ToolbarOverflowPanel that is built in to the toolbar control. You can control how the overflow is handled by setting the OverFlowMode property, using SetOverflowMode.

另外,如果您使用 ToolBarTray 容器,您可以设置工具栏的方向。

例如:

<ToolBarTray Orientation="Vertical">
    <ToolBar>
        <Button Content="A" />
        <Button Content="B" />
        <Button Content="C" />
    </ToolBar>
</ToolBarTray>