c# - 为什么我的 WPF 单选按钮没有与中心垂直对齐?

标签 c# wpf

我有一个 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>
// ...

这是它的样子:

Radio button alignment

如何让单选按钮垂直居中?

最佳答案

为 RadioButton 设置 VerticalContentAlignmentCenter:

<RadioButton Margin="0,5,0,0" DockPanel.Dock="Top"
             VerticalContentAlignment="Center">
  .....
</RadioButton>

关于c# - 为什么我的 WPF 单选按钮没有与中心垂直对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25008776/

相关文章:

wpf - 将一些 WPF 窗口放入 DLL

c# - 将节点添加到 ViewModel 时自动更改 TreeView 的选择

wpf - WPF Dispatcher 是多线程问题的解决方案吗?

c# - ListView ItemActivate 延迟

c# - 在 csproj 中,我可以有条件地包含基于运行时标识符的文件吗?

wpf - 在WPF中打印多页

wpf - 如何计算wpf控件的总渲染时间?

c# - 如何延迟停止和启动函数应用

c# - 无法将 int 转换为 byte

c# - 继续返回任务的方法