Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 76418

Where is the flaw in this method of using WeakReference with ContentPages in XF?

$
0
0

When using weak references to re-use pages in XF, is there anything that needs to be done when re-using a page? I am finding on a tiny minority of pages that the page when shown for a second time is not laid out correctly. Simply calling InvalidateMeasure() on the page does not do the trick. It's feels as if I need to InvalidateMeasure on every view on the page, but that's so hacky that I'm hoping there's a better way that I just haven't spotted.

The pattern I have followed for using WeakReference with pages is as follows:

    private static WeakReference termsAndConditionsPageView = null;

    TermsAndConditionsPageView page
        = (termsAndConditionsPageView != null) && (termsAndConditionsPageView.IsAlive)
        ? termsAndConditionsPageView.Target as TermsAndConditionsPageView
        : null;
    if (page == null)
    {
        page = new TermsAndConditionsPageView();
        termsAndConditionsPageView = new WeakReference(page);
    }

    await Navigation.PushAsync(page, false);

Any help much appreciated. Note that although I think (not 100% sure) I have seen this on other platforms, I am only currently seeing this on Windows.

Thanks,

John H.


Viewing all articles
Browse latest Browse all 76418

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>