A.D. A.D. - 1 year ago 65
C# Question

WPF UserControls display left when I specify HorizontalAlignment="Right"

This is my WPF UserControl code reduced to the relevant part:

<UserControl x:Class="AKPS.View.UserCalibWindow"

<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Width="1600" >
<Button Height="45" Width="100" />
<Button Height="45" Width="100" />

Why do the 2 buttons display on the left?

Answer Source

A StackPanel does exactly that - it stacks elements together, in your case, horizontally. Your HorizontalAlignment is referring to the stack panel, which will shift it to the right, not the buttons inside them.

Instead, perhaps try using a Grid instead of a StackPanel, and then placing your StackPanel (with no Width element set) inside it.