Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8788081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:04:53+00:00 2026-06-13T22:04:53+00:00

The common question about positioning an element inside a Canvas is How to position

  • 0

The common question about positioning an element inside a Canvas is “How to position the center of element (instead of the top left corner)”.

  • WPF: Resizing a circle, keeping the center point instead of TopLeft?
  • WPF Center Ellipse at X, Y
  • WPF element positioning on a Canvas

Several solutions are presented, but they all have drawbacks.

The easiest solution is to accommodate the element size during while setting the Canvas.Left and Canvas.Top properties programmatically. This works, but only once. This solution doesn’t support bindings and it will break when the element size is changed. You also cannot set the Canvas.Left or Canvas.Top using

Another set of solutions involve translate transformations utilizing either RenderTransform or Margin. These solutions require binding some property to the -0.5 * Width or -0.5 * Height. Such binding requires creating a custom ValueConverter and is impossible to create using only XAML.

So, is there a simple way to position an element inside canvas so that its Canvas.Left and Canvas.Top correspond to the element’s center and both size and position properties can be bound to some other properties?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:04:54+00:00Added an answer on June 13, 2026 at 10:04 pm

    XAML and bindings seem very powerful, but sometimes there are simple problems that require very complex solutions. In my bindings library creating such binding would be as easy as writing element.Center = position or element.TopLeft = position - element.Size / 2, but don’t let me get carried away.

    I’ve found a very simple solution which uses only XAML and supports binding both size and position properties of the element. It seems that when the WPF control with alignment set too Stretch or Center is placed inside the canvas, the element “gravitates” towards centering as the (Canvas.Left, Canvas.Top) point (the state that we desire), but is stopped by the “angle plate” placed at the same (Canvas.Left, Canvas.Top) point. How do I know about this “gravitation”? It’s evident when you ease the block by setting the Margin of the element to a negative value. Setting the negative margin allows the element to move towards its center goal. The element moves until the Margin reaches (-Height / 2, -Width / 2) so that the element becomes perfectly centered at the (Canvas.Left, Canvas.Top) point. Further changes don’t cause any movement since the element is already perfectly positioned.

    Solution: set Margin="-1000000".

    So in the following code the ellipses are both centered at the (200, 200) point. The first ellipse has Left and Top properties corresponding to the ellipse center allowing to easily bind them with some other objects’ properties.

    <Canvas>
        <Ellipse Width="100" Height="100" Canvas.Left="200" Canvas.Top="200" Opacity="0.5" Fill="Red" Margin="-100000" />
        <Ellipse Width="100" Height="100" Canvas.Left="150" Canvas.Top="150" Opacity="0.5" Fill="Blue" />
    </Canvas>
    

    The bad thing is this solution only work in WPF. Silverlight and WinRT don’t have the described behavior.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quick question about include/requre_once . I have some code that is common to a
this question is about style, because i think this is a very common problem
This is not the apparently-common question about how to put text over a background
I have what I believe to be a common question about using a subform
I have a question about CETP(Common Expect Test Platform), it is a TCL testing
i have a question about how to do a common programming task in linq.
I've got a question about windowdependant CSS'es. It's a very common question, but somehow
A common question that comes up from time to time in the world of
This is a common question, but the explanations found so far and observed behaviour
I am sure this is a common question, but since I'm really new to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.