我有一个TextBox
我想延伸到其父母的Width
.
我尝试锚定上、左、右,但仅超过 60%,有什么想法吗?
正如汉斯帕桑特在评论中所说,但也锚定在左边。
或者,如果您想以编程方式执行此操作:
textBox1.Width = textBox1.Parent.Width;
textBox1.Location = new Point(0,textBox1.Location.Y);
textBox1.Anchor = AnchorStyles.Left | AnchorStyles.Right;
在 WPFActualWidth
中,对父控件的属性使用 Binding(在本例中为它的命名容器):
Width="{Binding Container, Path=ActualWidth}"
另一种可能性是(如果您没有命名控件并且只想绑定到父控件):
Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ActualWidth}"
在 Windows 应用商店、Windows Phone 8.0 和 8.1、WPF 和所有基于 XAML 的 UI 平台中,可以使用属性
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"