WPF 面板中的停靠按钮

发布于 2024-12-21 20:44:03 字数 194 浏览 4 评论 0原文

怎么办呢?例如,如果菜单式面板中有四组按钮。如果调整窗口大小,您将如何将它们停靠到初始位置?

我正在尝试使用 DockPanel 和 Horizo​​ntalAlign,但它似乎只适用于调整窗口大小时右侧的最后一个按钮。但是如何停靠(锚定)一组按钮呢?也许将它们放在边框对象中并使用 Horizo​​ntalAlign 来实现?有更优雅的方法来做到这一点吗?

How can it be done? If there are, for example, four groups of buttons in menu-like panel. How would you dock them to their initial location if the window is resized?

I am trying this using DockPanel and HorizontalAlign, but it seems to only be work for the last button on the right when the window is resized. But how do you dock(anchor) a group of buttons? Maybe put them in border object and use HorizontalAlign for it? Is there more elegant way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

魔法少女 2024-12-28 20:44:03

总结一下评论:我不知道你的背景,但你似乎习惯了另一种 UI 设计方式,在这种方式中你不必在代码中明确指定分组等。虽然这看起来更优雅,但事实并非如此:设计器生成的代码很糟糕,整个系统不像 WPF 为您提供的那样灵活或直接。

使用 WPF,您可以在您的意图之间获得清晰的一对一关系( 将按钮视为布局中的一个组)和实际代码(将按钮放入堆栈面板/网格/...)。或者在按钮周围绘制边框,并在边框内垂直组织它们,而在 xaml 中使用内部带有堆栈面板的边框。没有比这更优雅的了。

阅读 WPF 布局,一旦掌握了它,您很快就会发现它既强大又美观。我发现本教程在刚开始使用布局时非常有用。像往常一样,谷歌提供了很多很多更多的信息。

To summarize the comments: I don't know your background but it seems you are used to another way of UI design where you do not explicitely have to specify grouping etc in code. While that might seem more elegant, it is not: the designer generated code is awful and the whole system is not as flexible nor srtaightforward as what WPF gives you..

With WPF you get a clear one-to-one relationship between your intent (treating buttons as a group within a layout) and the actual code (put the buttons in a stackpanel/grid/...). Or draw a border around buttons and organize them vertically within the border vs in xaml use a border with a stackpanel inside. It won't get any more elegant than that.

Read up on WPF layouts and once you'll get a grip of it you will quickly see that it is rather powerful and beatiful at the same time. I found this tutorial pretty helpful when just starting with layouts. And google provides lots and lots and lots more information, as usual.

披肩女神 2024-12-28 20:44:03

就像 stijn 所说,将按钮放在 Grid 或 Stackpanel 中就可以了。
您可能不认为它很漂亮,但它是解决您问题的最佳解决方案。

Like stijn said, put the buttons in a Grid or a Stackpanel and you'll be fine.
You may not think it's beautifull, but it's the best solution for your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文