我试图让第一个标签和文本框与屏幕左侧对齐,第二个标签和文本框与屏幕右侧对齐。我在这里错过了什么?第二组控件不会与右侧对齐。
提前致谢!
round
答案 0 :(得分:0)
外线StackPanel
是你的问题。请改用Grid
。您的问题实际上是Aligning controls on both left and right side in a stack panel in WPF
以下是Grid
的代码:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal">
<Label Content="Active Profile"></Label>
<TextBox Name="activeProfileName" Width="100" Height="20"></TextBox>
</StackPanel>
<StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Right" >
<Label Content="Create A New Profile"
HorizontalAlignment="Right"></Label>
<TextBox Name="activeProfileNamey"
Width="100" Height="20"
HorizontalAlignment="Right"></TextBox>
</StackPanel>
</Grid>
</Grid>