为什么我的WPF单选按钮垂直居中对齐

为什么我的WPF单选按钮垂直居中对齐

本文介绍了为什么我的WPF单选按钮垂直居中对齐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在那里我试图用单选按钮来确定哪些文本框输入使用WPF项目。当我运行它,不过,单选按钮本身对准到容器的顶部,我无法找到任何一种取向性的影响它。这种行为是正常吗?我一直在寻找答案,但一切似乎都问如何垂直对齐的单选按钮。我的假设是,它涉及到如何我有它嵌套在其他控制,但我怎么能使其在不改变太多的工作?

I have a WPF project where I'm trying to use radio buttons to determine which TextBox input to use. When I run it, though, the radio button itself is aligned to the top of the container, and I cannot find any sort of alignment property that affects it. Is this behavior expected? I've been searching for answers but everything seems to be asking how to align the radio button vertically. My assumption is that it's related to how I have it nested in other controls, but how can I make it work without changing too much?

这是相关的的XAML单选按钮:

This is the xaml relevant to the radio buttons:

        <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>
// ...

这是什么样子:

我怎样才能得到单选按钮垂直居中?

How can I get the radio buttons to be centered vertically?

推荐答案

VerticalContentAlignment 中心 作为单选:

Set VerticalContentAlignment as Center for RadioButton:

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

这篇关于为什么我的WPF单选按钮垂直居中对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 08:22