ssb ssb - 1 year ago 190
C# Question

Why aren't my WPF radio buttons vertically aligned to the center?

I have a WPF project where I'm trying to use radio buttons to determine which

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?

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 Margin="0,5,0,0" DockPanel.Dock="Top">
<StackPanel Orientation="Horizontal">
<TextBox Name="Hours" Width="30" VerticalAlignment="Center" >0</TextBox>
<TextBox Name="Minutes" Width="30" VerticalAlignment="Center">0</TextBox>
<TextBox Name="Seconds" Width="30" VerticalAlignment="Center">0</TextBox>
// ...

This is what it looks like:

Radio button alignment

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

Answer Source

Set VerticalContentAlignment as Center for RadioButton:

<RadioButton Margin="0,5,0,0" DockPanel.Dock="Top"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download