简体   繁体   中英

Xamarin Forms: Freeze screen on navigation back button

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.

我只是在ViewBase.cs上实现“ IDestructable”,并将“ GC.Collect()”放在调用库方法之前,但它停止运行。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM