How to position a WPF Button?

If you place a button on a Grid control, the button will be placed in the center of Grid. If you are using a Canvas as your parent control of Button, the Button will be placed in the left top corner of Canvas.

You can use Margin property to position a button control. If you are using a Canvas, you may also use Canvas.Left and Canvas.Top properties.

You may also use VerticalAlignment and HorizontalAlignment attributes to set vertical alignment, and horizontal alignment of a button.

The code snippet in Listing 2 sets the position of the Button control in the left top corner of the page.

<Button x:Name="DrawCircleButton" Height="40" Width="120"

        Canvas.Left="10" Canvas.Top="10"

        Content="Draw Circle"

        VerticalAlignment="Top"

        HorizontalAlignment="Left">

</Button>