8

I want to set position attribute of an UIElement to an absolute value of X and Y. How can I do this operation? And why absolute positioning in UWP is so hard?

n.y
  • 3,343
  • 3
  • 35
  • 54
  • 10
    Put it in a Canvas, and set the `Canvas.Left` and `Canvas.Top` to the desired x and y values. – Clemens Feb 01 '16 at 11:01
  • 7
    "why absolute positioning in UWP is so hard" - because UWP apps are mostly responsive. If you develop a responsive design, you hardly ever use absolute positions. – sibbl Feb 01 '16 at 11:25
  • 1
    If the answer of @Clemens isn't appropriate, you can also set the `Margin` property of your element – Kevin Gosse Feb 01 '16 at 13:40
  • Omg, Thank you! >.< I am so tired of not having any control over where things go. It'd be really nice if you could opt out of the ResponsiveUI crap for specific projects. Why am I using UWP, then? Because the only working GUI that I can find for .NET Linux coding is UWP based. (UnoPlatform). But, guess what? Industrial clients could care less if it's responsive - they want the sizes to be set to specifics in every aspect of the program, so that it conforms to their UI standards. And, with the shift from Windows to Linux, I can't use WinForms anymore. So, this is a Gold Mine to me. Thank you! – CherryCoke Mar 08 '21 at 03:41

2 Answers2

1

First of all, absolute position in UWP is so hard, because GUI child elements built relative to the parent element(Page, Grid and etc) You can see, that if you open documentation to UIElement and open Property ActualOffset, you can see, that:

Gets the position of this UIElement, relative to its parent, computed during the > arrange pass of the layout process.

But you can change the point relative to which the coordinates are calculated by class GeneralTransform. Example you can see in this ticket.

Alexander
  • 21
  • 5
1

Maybe this will be helpfull Canvas.SetLeft && Canvas.SetTop

excommunicado
  • 287
  • 1
  • 10
  • Note, this risks being perceived as a link-only answer and being flagged as not an answer. I think the mentioning of the features alone is more than link-only. But you might want to write a little more directly here. – Yunnosch Jul 27 '22 at 07:55