Rotate an image around center

I'm trying to rotate an image, but the rotation is always around upper left corner. Is there a way to make the photo rotate around center?




  • StephaneDelcroixStephaneDelcroix USInsider, Beta ✭✭✭✭

    yes, set the AnchorX and AnchorY properties to 0.5.

  • christianmassironichristianmassironi ITMember
    edited October 2014

    Many Thanks Stephane for your reply.
    I've tried with 0.5, but it's not working. It works using 0.505, but the results is not perfect.
    For the use that I need is good, but It's a strange behavior.

  • FabienComteFabienComte FRMember

    Maybe your "visible" part of image is not centered (case of png with transparent color) ?

  • No, it's a jpg taken with the phone's camera.

  • AndyHopperAndyHopper USMember ✭✭
    edited October 2014

    @StephaneDelcroix‌, I'm on XF 1.2.3 and am seeing animations rotate around 0,0 even when I'm explicitly setting Anchor X/Y each to .5. I saw a mention that there may be a regression; does that regression affect 1.2.3?

  • LuckyDayLuckyDay USMember ✭✭✭

    I'm seeing this as well... any new information? Did you ever get this working @AndyHopper‌?

  • AndyHopperAndyHopper USMember ✭✭
    edited December 2014

    I ended up using a hack I saw elsewhere: right before I start the rotate animation I explicitly set the element's AnchorX/Y properties to 0, then back to .5. Also, since my code needed the ability to start the animation immediately I found that I needed to have it run a few hundred milliseconds after the layout was created to give the forms engine time to determine boundaries, etc. The recipe I ended up with was
    private async StartAnimation() { // Wait for Forms to lay everything out await Task.Delay(250); someElement.AnchorX = 0; someElement.AnchorY = 0; someElement.AnchorX = 0.5; someElement.AnchorY = 0.5; // Start animation here }
    Without that delay, even this AnchorX/Y reset worked sporadically if I started the animation immediately after the form appeared. I'm sure you could put it somewhere else; it was simpler for me to just chuck it in there to guarantee that I had waited long enough no matter when it was called.

    EDIT: I should add that there's at least one BugZilla entry for this. Doesn't appear to have been much activity on it lately.

  • LuckyDayLuckyDay USMember ✭✭✭

    Awesome, works great! Thanks much.

    I've had the same issue with changes not being picked up if I set them during the layout cycle and did pretty much the same thing. Silly workarounds but whatever, if it works it works and it's not too messy.

    Thanks again.

Sign In or Register to comment.