As an optimisation, for certain pages within my app, I have tried holding on to a weak reference to the page and then re-using the page, rather than re-creating it each time. The code is based on the below. However, on specific pages, when the page is displayed for a second or subsequent time (after popping out of the original), the layout is not as expected. It seems that the layout needs to be re-calculated, but adding in a call to InvalidateMeasure() does not make this happen. Does anybody know of a way to solve this, or is it a case of getting rid of the weak references again?
private static WeakReference pageView = null;
PageView page
= pageView != null
? pageView.Target as PageView
: null;
if (page == null)
{
page = new PageView();
pageView = new WeakReference(page);
}
await this.Navigation.PushAsync(page, animate);
Thanks,
John H.