convert xamarin rerender to maui handler

Thinh NPD 40 Reputation points
2024-12-23T04:30:38.4966667+00:00

i have trouble migrating xamarin rerender to maui handler. Here's the code [assembly: ExportRenderer(typeof(CustomNavigationPage), typeof(CustonNavigationRenderer))]

namespace Test.App.Business

{

   public class CustomNavigationRenderer : NavigationPageRenderer  

   {  

       public CustomNavigationRenderer(Context context) : base(context)  

       {  

       }  


 

       protected override void SetupPageTransition(AndroidX.Fragment.App.FragmentTransaction transaction, bool isPush)  

       {  

           //base.SetupPageTransition(transaction, isPush);  

           if (isPush)  

           {  

               transaction.SetCustomAnimations(Resource.Animation.EnterFromRight, Resource.Animation.ExitToLeft,  

                                               Resource.Animation.EnterFromLeft, Resource.Animation.ExitToRight);  

           }  

           else  

           {  

               transaction.SetCustomAnimations(Resource.Animation.EnterFromLeft, Resource.Animation.ExitToRight,  

                                               Resource.Animation.EnterFromRight, Resource.Animation.ExitToLeft);  

           }  

       }  

   }  
```   }
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,763 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 46,206 Reputation points Microsoft Vendor
    2024-12-24T03:01:05.1466667+00:00

    Hello,

    The SetupPageTransition method has been canceled in Maui and is not inherited to NavigationViewHandler. This is because Maui now supports adding transition animations to controls in a cross-platform way.

    You can implement a custom NavigationPage with animations to display animation effects when performing Push and Pop operations.

    For example:

    public class AnimatedNaivgationPage: NavigationPage
    {
        public async void AnimatedPushAsync(Page page)
        {
            // add custom animation here.
            page.TranslateTo(...)
            await this.PushAsync(page);
        }
        public async void AnimatedPopAsync()
        {
            this.CurrentPage.TranslateTo(...)
            await this.PopAsync();
        }
    }
    

    You could refer to the following API documentation for more details about adding animation into controls.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

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