0
votes

I have a problem navigating within the application. When I use both the hardware and action bar buttons to return to my MainPage after a few times I can no longer navigate, sometimes the screen even freezes, I searched a lot and read somewhere that could be something in the background of the main page, the my case the page as a CustomRenderer, but it should not be a problem, because it still navigates a few times, I tried removing the Gradient from the background leaving white (default), until navigated a little more but continues to freeze the app or just not browsing anymore .

It is worth registering that inserting a breakpoint in the command that makes the navigation, in 100% of the times it still passes in the line to navigate, I do not know what can be happening.

Used Framework: PRISM

App.xaml.cs:

protected override async void OnInitialized()
        {
            InitializeComponent();

            await NavigationService.NavigateAsync("NavigationPage/" + nameof(DashboardPage));
        }

Gradient Renderer example:

public class GradientPageRenderer : PageRenderer
    {
        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);

            if (e.OldElement == null) // perform initial setup
            {
                var page = e.NewElement as ContentPage;
                var gradientLayer = new CAGradientLayer();
                gradientLayer.Frame = View.Bounds;
                gradientLayer.Colors = new CGColor[]
                {
                    ((Color)App.Current.Resources["DefaultGreenColor"]).ToCGColor(),
                    ((Color)App.Current.Resources["DefaultPurpleColor"]).ToCGColor()
                };
                View.Layer.InsertSublayer(gradientLayer, 0);
            }
        }
    }

The problem occurs on iOS and Android.

1
The if condition should probably read "e.NewElement != null". See also Creating the Custom Renderer on each PlatformBenl

1 Answers

0
votes

I Just implement "IDestructable" on my ViewBase.cs and put "GC.Collect()" before call base method and it stops to break.