我正在动态创建标签、文本框和按钮。我需要 Button 与其右侧的文本框出现在同一行中。
这是我正在使用的代码:
Label lbl = new Label()
{
Content = "Some Label",
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
HorizontalContentAlignment = HorizontalAlignment.Center,
VerticalContentAlignment = VerticalAlignment.Center,
Height = 28,
};
TextBox tb = new TextBox()
{
Text = "Some Text",
IsReadOnly = true,
};
Button btn = new Button()
{
Content = "Click Me",
HorizontalAlignment = HorizontalAlignment.Left
Margin = new Thickness(tb.ActualWidth),
};
我将按钮边距分配给 TextBox 的右侧,但它仍然出现在文本框下的下一行中。
我在这里做错了什么?