我有一个 WPF 项目,我在其中尝试使用单选按钮来确定要使用哪个 TextBox
输入。但是,当我运行它时,单选按钮本身与容器的顶部对齐,我找不到任何影响它的对齐属性。这种行为是预期的吗?我一直在寻找答案,但似乎一切都在询问如何垂直对齐单选按钮。我的假设是它与我如何将它嵌套在其他控件中有关,但我如何才能在不进行太多更改的情况下使其正常工作?
这是与单选按钮相关的 xaml:
<DockPanel Grid.Column="1" Margin="5,0,0,0">
<RadioButton HorizontalContentAlignment="Stretch" DockPanel.Dock="Top" IsChecked="True">
<xctk:TimePicker Name="TimePickerBox" Margin="0" Format="LongTime"
VerticalAlignment="Center"/>
</RadioButton>
<RadioButton Margin="0,5,0,0" DockPanel.Dock="Top">
<StackPanel Orientation="Horizontal">
<TextBox Name="Hours" Width="30" VerticalAlignment="Center">0</TextBox>
<Label>Hours</Label>
<TextBox Name="Minutes" Width="30" VerticalAlignment="Center">0</TextBox>
<Label>Minutes</Label>
<TextBox Name="Seconds" Width="30" VerticalAlignment="Center">0</TextBox>
<Label>Seconds</Label>
</StackPanel>
</RadioButton>
// ...
这是它的样子:
如何让单选按钮垂直居中?
最佳答案
为 RadioButton 设置 VerticalContentAlignment
为 Center
:
<RadioButton Margin="0,5,0,0" DockPanel.Dock="Top"
VerticalContentAlignment="Center">
.....
</RadioButton>
关于c# - 为什么我的 WPF 单选按钮没有与中心垂直对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25008776/