为什么文本框不拉伸(stretch)以填充堆栈面板中的空间?这是设计使然吗?在网格中,文本框按预期拉伸(stretch)。
最佳答案
肯特的回答似乎是对的。
为了仍然强制覆盖 StackPanel 行为,我认为您需要动态计算设置包含元素的 Width 属性或 MeasureOverride 的一些时髦覆盖.我宁愿使用另一个布局管理器/面板。我注意到的一些事情..
StackPanel
The default value is stretch for both HorizontalAlignment and VerticalAlignment of content that is contained in a StackPanel.
HorizontalAlignment
When Height and Width properties are explicitly set on an element, these measurements take higher precedent during layout and will cancel the typical effects of setting HorizontalAlignment to Stretch.
关于WPF - 在 StackPanel 中设置 HorizontalAlignment= 拉伸(stretch)到文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/405935/