[英]How to set multiple buttons, textblocks and textboxes underneath each other in WPF?
Right now I have the following:现在我有以下内容:
<DockPanel Height="150">
<Button DockPanel.Dock="Right" Padding="5" Margin="5 0 5 0" FontWeight="Bold" Content="Submit" Click="Button_Click"/>
<TextBlock TextAlignment="Left" Padding="5" Text="DVM Positive Readout" />
<Border Height="25" BorderBrush="Black" BorderThickness="1" DockPanel.Dock="Top">
<TextBox HorizontalAlignment="Stretch" VerticalAlignment="Center" x:Name="DVM_Positive_ReadOut" LostKeyboardFocus="DVM_Positive_ReadOut_LostKeyboardFocus" />
</Border>
<Border Height="25" BorderBrush="Black" BorderThickness="1" DockPanel.Dock="Top">
<TextBox HorizontalAlignment="Stretch" VerticalAlignment="Center" x:Name="DVM_Negavtive_ReadOut" LostKeyboardFocus="DVM_Negative_ReadOut_LostKeyboardFocus" />
</Border>
</DockPanel>
I want to have two submit buttons and two textblocks.我想要两个提交按钮和两个文本块。 The Textboxes are correctly stacked, though it would be nice if they were centered.文本框正确堆叠,但如果它们居中就更好了。
You can achieve this by using StackPanel with its horizontal or vertical attribute:您可以通过使用 StackPanel 及其水平或垂直属性来实现此目的:
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock TextAlignment="Left"
Padding="5"
Text="DVM Positive Readout"
Width="150"/>
<Border Height="25"
BorderBrush="Black"
BorderThickness="1"
Width="150"
DockPanel.Dock="Top">
<TextBox HorizontalAlignment="Stretch"
VerticalAlignment="Center"
x:Name="DVM_Positive_ReadOut"
LostKeyboardFocus="DVM_Positive_ReadOut_LostKeyboardFocus" />
</Border>
<Button DockPanel.Dock="Right"
Padding="5"
Margin="5 0 5 0"
FontWeight="Bold"
Content="Submit"
Click="Button_Click" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock TextAlignment="Left"
Padding="5"
Text="DVM Negative Readout"
Width="150" />
<Border Height="25"
BorderBrush="Black"
BorderThickness="1"
Width="150"
DockPanel.Dock="Top">
<TextBox HorizontalAlignment="Stretch"
VerticalAlignment="Center"
x:Name="DVM_Negavtive_ReadOut"
LostKeyboardFocus="DVM_Negative_ReadOut_LostKeyboardFocus" />
</Border>
<Button DockPanel.Dock="Right"
Padding="5"
Margin="5 0 5 0"
FontWeight="Bold"
Content="Submit"
Click="Button_Click" />
</StackPanel>
</StackPanel>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.