WPF 工具栏中的控件之间的动态间距
我有一个工具栏,其中包含多个控件,例如 10 个。
我想将最后三个控件放置在工具栏的右上角,并在这三个控件和其余控件之间留出一些空间。
当我调整窗口大小时,它应该减少空间,一旦没有空间,就应该将其一一剪辑到溢出下拉列表中。
注意:我只需要使用一个工具栏。
I have a toolbar which contains several controls, say 10.
I want to place last three controls in the right corner of the tool bar with some space between these three controls and remaining controls.
When I resize the window, it should reduce the space, once there is no space it should be cliped to overflow drop down one by one.
Note: I need to use only one toolbar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我之前做过一次
这些项目存在于自定义的
ScrollViewer
中,因此它们可以离开屏幕,并且ScrollViewer
的SizeChanged
事件会检查每个项目都可以查看它是否在屏幕外。如果它不可见或部分可见,则该项目将被隐藏,并且数据对象将被添加到菜单
中。如果该项目可见,它会将其从Menu
中删除(如果它存在),并将其设置为可见。Menu
仅在包含项目时才可见。这是不久前我刚接触 WPF 时完成的,所以我确信这个过程可以改进。
下面列出了我用来确定项目可见性的辅助类
它可以像这样使用:
I did this once before
The items existed in a customized
ScrollViewer
so they could go off-screen, and theSizeChanged
event of theScrollViewer
would check each item to see if it was off-screen or not. If it wasn't visibile, or was partially visible, then the item would get hidden and the data object would get added to aMenu
. If the item was visible, it would remove it from theMenu
if it existed there, and set it visible. TheMenu
was only visible if it had items.This was done a while back when I was still new to WPF, so I'm sure the process could be improved on.
The helper class I used to determine item visibility is listed below
It could be used like this: