【发布时间】:2011-11-14 21:01:59
【问题描述】:
我有一个TextBox,我想将它延伸到其父级的Width。
我尝试锚定上、左、右,但仅超过 60%,有什么想法吗?
【问题讨论】:
-
使其与设计器中的父级宽度相同,然后将其锚定到右侧。
-
你在用什么?表格? ASP.NET? WPF?还有什么?
标签: c# winforms textbox width stretch
我有一个TextBox,我想将它延伸到其父级的Width。
我尝试锚定上、左、右,但仅超过 60%,有什么想法吗?
【问题讨论】:
标签: c# winforms textbox width stretch
在 Windows 应用商店、Windows Phone 8.0 和 8.1、WPF 和所有基于 XAML 的 UI 平台中,可以使用属性
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
【讨论】:
正如 Hans Passant 在评论中所说,但也锚定在左侧。
或者,如果您想以编程方式进行:
textBox1.Width = textBox1.Parent.Width;
textBox1.Location = new Point(0,textBox1.Location.Y);
textBox1.Anchor = AnchorStyles.Left | AnchorStyles.Right;
【讨论】:
在 WPF 中,对父控件的属性 ActualWidth 使用 Binding(在本例中为它的命名容器):
Width="{Binding Container, Path=ActualWidth}"
另一种可能性是这样(如果您没有命名控件而只想绑定到父控件):
Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ActualWidth}"
【讨论】: