2

我有一个TextBox我想延伸到其父母的Width.

我尝试锚定上、左、右,但仅超过 60%,有什么想法吗?

4

3 回答 3

6

正如汉斯帕桑特在评论中所说,但也锚定在左边。

或者,如果您想以编程方式执行此操作:

textBox1.Width = textBox1.Parent.Width;
textBox1.Location = new Point(0,textBox1.Location.Y);
textBox1.Anchor = AnchorStyles.Left | AnchorStyles.Right;
于 2011-09-11T20:24:45.943 回答
0

在 WPFActualWidth中,对父控件的属性使用 Binding(在本例中为它的命名容器):

Width="{Binding Container, Path=ActualWidth}"

另一种可能性是(如果您没有命名控件并且只想绑定到父控件):

Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ActualWidth}"
于 2011-09-11T18:39:39.797 回答
-2

在 Windows 应用商店、Windows Phone 8.0 和 8.1、WPF 和所有基于 XAML 的 UI 平台中,可以使用属性

VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
于 2015-03-30T14:44:02.880 回答