pop up animation

Eduardo Gomez Romero 1,355 Reputation points
2024-09-28T18:10:20.6733333+00:00

I have an poup that is opening with an animation

 private async void PopUpBorder_Loaded(object sender, EventArgs e) {
     PopUpBorder.Scale = 0.5;
     PopUpBorder.Opacity = 0;
     await Task.WhenAll(new Task[]
     {
          PopUpBorder.ScaleTo(1, 500, Easing.CubicInOut),
          PopUpBorder.FadeTo(1, 500, Easing.CubicInOut)
     });
 }

https://reccloud.com/u/1o1r2a1

but when I close it, it closes from the upper left, and I want to close it from the center
like the way I open it

  private static async Task ExiitAnimation(Popup popup) {
      if (popup.Content is VisualElement popUpBorder) {
          // Set the anchor to the center
          popUpBorder.AnchorX = 0.5;
          popUpBorder.AnchorY = 0.5;
          await Task.WhenAll(new Task[]
          {
              popUpBorder.ScaleTo(0.5, 500, Easing.CubicInOut),
              popUpBorder.FadeTo(0, 500, Easing.CubicInOut)
          });
          popup.Close();
      }
Developer technologies | .NET | .NET Multi-platform App UI
0 comments No comments

2 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    2 deleted comments

    Comments have been turned off. Learn more

  2. Rolle Michel 75 Reputation points
    2024-09-29T13:15:06.4+00:00

    To ensure your popup closes from the center, you need to adjust the AnchorX and AnchorY properties before starting the exit animation. It looks like you're on the right track. Just make sure you're setting those anchors to 0.5 for both axes. Here’s a revised version of your exit animation method:

    private static async Task ExitAnimation(Popup popup) {
        if (popup.Content is VisualElement popUpBorder) {
            // Set the anchor to the center
            popUpBorder.AnchorX = 0.5;
            popUpBorder.AnchorY = 0.5;
            // Optionally reset scale and opacity before starting the animation
            popUpBorder.Scale = 1;
            popUpBorder.Opacity = 1;
            await Task.WhenAll(new Task[]
            {
                popUpBorder.ScaleTo(0.5, 500, Easing.CubicInOut),
                popUpBorder.FadeTo(0, 500, Easing.CubicInOut)
            });
            
            popup.Close();
        }
    }
    
    

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.