这看起来应该很简单,但我被难住了。在WPF中,我希望TextBox能够延伸到它的父元素的宽度,但只能达到最大宽度。问题是我希望它在它的父级中保持左对齐。要让它拉伸,你必须使用HorizontalAlignment=" stretch ",但结果是居中的。我已经用HorizontalContentAlignment做过实验,但它似乎什么也做不了。
如何使这个蓝色文本框与窗口大小一起增长,最大宽度为200像素,并保持左对齐?
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel>
<TextBox Background="Azure" Text="Hello" HorizontalAlignment="Stretch" MaxWidth="200" />
</StackPanel>
</Page>
诀窍是什么?
https://stackoverflow.com/questions/280331
复制相似问题