WPF 中的 StackPanel 和 DockPanel 有什么区别?
什么是 DockPanel
可以做 StackPanel
不能做的事情?如果有人有一个可以使用 StackPanel 而不是 DockPanel 实现的图像,那就太好了。
What can a DockPanel
do that a StackPanel
cannot? If anyone has an image of something that can be achieved with a StackPanel
, but not a DockPanel
, than that would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Stack Panel:
StackPanel
,顾名思义,可以水平或垂直排列内容。垂直是默认值,但可以使用Orientation
属性进行更改。内容会根据方向自动拉伸(请参见下面的屏幕截图),这可以通过更改HorizontalAlignment
或VerticalAlignment
属性来控制。Dock Panel:
DockPanel
用于锚定将元素放置在容器的边缘,是设置应用程序 UI 整体结构的不错选择。使用DockPanel.Dock
附加属性来停靠元素。元素停靠的顺序决定了布局。Stack Panel: The
StackPanel
, as the name implies, arranges content either horizontally or vertically. Vertical is the default, but this can be changed using theOrientation
property. Content is automatically stretched based on the orientation (see screenshot below), and this can be controlled by changing theHorizontalAlignment
orVerticalAlignment
properties.Dock Panel: The
DockPanel
is used to anchor elements to the edges of the container, and is a good choice to set up the overall structure of the application UI. Elements are docked using theDockPanel.Dock
attached property. The order that elements are docked determines the layout.