I have the following code:
<DockPanel>
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal">
<RadioButton Content="_Programs"
IsChecked="{Binding Path=ProgramBanksSelected}" IsEnabled="{Binding Path=ProgramsEnabled}" Margin="8" />
<StackPanel>
<Label Content="Master" Height="28" Name="MasterFileStatus" VerticalContentAlignment="Center"/>
</StackPanel>
</StackPanel>
...
The radio button should be placed on the left side in the stack panel (I removed some buttons for not cluttering the example) and the label (which I put temporarily in a nested StackPanel) should be on the right side.
I tried already lots of combinations of alignments but I cannot get the label on the right side. What should I add to accomplish this?
Even though this is old, should someone come across this like I did, here's a simple solution.
Make a new grid and inside that grid put two stack panels with different Horizontal Alignment.
The possible issue is that now without extra handling the two could overlap with each other.
User @pasx is right. You should use DockPanel and dock the RadioButton to the left side, and your StackPanel with the label to the right side.
Just do not use a
StackPanel
,StackPanels
stack. They do, for obvious reasons, not allow alignment in the direction in which they stack. Use aGrid
, with column definitions like so:As you have set the
StackPanel
's orientation toHorizontal
, theHorizontalAlignment
property won't work on child-elements. You can keep theStackPanel
if you need additional controls, though I would recommend switching to aGrid
(among other things) to build the layout you want.Also, the
Grid
will allow you to control the actual width of each column: