---
title: "How to properly center a WPF canvas?"  
description: "How to properly center a WPF canvas?"  
author: "Anonymous User"  
published: 2013-09-24  
updated: 2013-09-24  
canonical: https://www.mindstick.com/forum/1513/how-to-properly-center-a-wpf-canvas  
category: "c#"  
tags: ["wpf"]  
reading_time: 1 minute  

---

# How to properly center a WPF canvas?

I have a [full](https://www.mindstick.com/articles/12893/experience-the-full-power-of-suitecrm) [screen](https://www.mindstick.com/forum/33644/loading-screen-during-ajax-call) [dialog](https://www.mindstick.com/forum/562/jquery-dialog-box-not-closed-in-asp-dot-net-mvc-4) and want to center a [canvas](https://www.mindstick.com/forum/1383/how-can-i-print-a-canvas-in-wpf). It seems to work well with a [grid](https://www.mindstick.com/forum/369/how-can-i-add-a-column-name-to-my-grid) with [Vertical](https://www.mindstick.com/forum/12951/how-to-fix-bootstrap-tab-vertical-with-text)/Horizontalalignment for a [Label](https://www.mindstick.com/articles/12835/print-label-tracking-how-do-these-features-make-auspost-woocommerce-plugin-better) for example, but when I try this the top [left](https://www.mindstick.com/articles/12768/don-t-be-left-behind-with-the-new-it-revolution) corner gets centered [instead of](https://www.mindstick.com/articles/330/triggers-in-sql-server) the middle of the canvas:

```
<Window    Title=""    Topmost="True" WindowStyle="None" WindowState="Maximized"    ><Grid>    <Grid VerticalAlignment="Center" HorizontalAlignment="Center">        <Canvas>            <Border Margin="20"                Background="White"                BorderBrush="Black"                BorderThickness="2"                Padding="20" >                <DockPanel Margin="10">                    <StackPanel DockPanel.Dock="Top" Margin="0 0 0 50"                                Orientation="Vertical">                       <Label FontSize="32" Content="Hello"></Label>                    </StackPanel>                    <StackPanel HorizontalAlignment="Right"                                DockPanel.Dock="Bottom"                                Orientation="Horizontal">                            <Label FontSize="32" Content="Hello"></Label>                    </StackPanel>                </DockPanel>            </Border>        </Canvas>    </Grid>
```

## Replies

### Reply by Pravesh Singh

Hi Ankita,

You can put the Border as child of Grid instead of Canvas. (The Grid can have more than one child) Try this:

```
<Window                Title=""    Topmost="True" WindowStyle="None" WindowState="Maximized"    >    <Grid>        <Canvas HorizontalAlignment="Stretch" VerticalAlignment="Stretch">            <Rectangle Canvas.Left="40" Canvas.Top="31" Width="630" Height="41" Fill="Blue" />            <Ellipse Canvas.Left="130" Canvas.Top="79" Width="580" Height="580" Fill="Blue" />            <Path Canvas.Left="61" Canvas.Top="28" Width="133" Height="98" Fill="Blue" Stretch="Fill" Data="M61,325 L293,28" />        </Canvas>        <Border Margin="20"                HorizontalAlignment="Center"                VerticalAlignment="Center"                Background="WhiteSmoke"                BorderBrush="Black"                BorderThickness="2"                Padding="20">            <DockPanel Margin="10">                <StackPanel DockPanel.Dock="Top" Margin="0 0 0 50" Orientation="Vertical">                    <Label FontSize="32" Content="Hello" />                </StackPanel>                <StackPanel HorizontalAlignment="Right"                                DockPanel.Dock="Bottom"                                Orientation="Horizontal">                    <Label FontSize="32" Content="Hello" />                </StackPanel>            </DockPanel>        </Border>    </Grid></Window>
```


---

Original Source: https://www.mindstick.com/forum/1513/how-to-properly-center-a-wpf-canvas

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
