简体   繁体   English

在WPF中调整控件的大小是否会调整其StackPanel的大小?

[英]Does resizing a control in WPF resize its StackPanel?

I have a Canvas inside of a StackPanel in my WPF Designer in Visual Studio 2008. At runtime I plan to resize the Canvas so its client rect is a certain size (borders and other parts are just added onto that size). 我在Visual Studio 2008的WPF设计器中的StackPanel中有一个Canvas。在运行时,我计划调整Canvas的大小,以便其客户端矩形为一定大小(将边框和其他零件添加到该大小上)。 When I resize the Canvas, will the Width/Height of the StackPanel adjust itself accordingly? 调整画布大小时,StackPanel的宽度/高度会相应调整吗? This is important since I have other controls that align themselves based on the size of the stack panel. 这很重要,因为我还有其他控件可根据堆栈面板的大小对齐。

The size of the stack panel is dependent upon the cumulative sizes of the controls (plus margins) that live inside the stack panel. 堆栈面板的大小取决于堆栈面板内部控件的累积大小(加上边距)。

So if your controls add up to 100px high, then the stack panel is only ever going to be 100px high. 因此,如果您的控件的高度总计为100px,则堆栈面板的高度只会达到100px。

实际上,一种替代选择是使用网格来调整大小,同时根据需要定义列/行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM