I am trying to overlay two xamarin pages on top of each other, one as the main, the other as a preview that can be expanded if needed. Akin to a spotify mini player that stays on top of the NavigationPage contents.
I have a custom page renderer where I create the child page renderer, add it to the parent's subviews then layout but... the child page ignores the layout and is always fullscreen.
protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
{
base.OnElementChanged(e);
var renderer=Platform.GetRenderer((Element as RootPage)?.Mini);
if (renderer == null)
{
renderer= Platform.CreateRendererWithContext(MiniPage, Context);
Platform.SetRenderer(MiniPage, renderer);
}
renderer.View.RemoveFromParent();
_miniView=renderer.View;
AddView(_miniView);
_miniView.Layout(0,Height-400,Width,400);
}
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
base.OnLayout(changed, l, t, r, b);
_miniView?.Layout(0, Height-400,Width, Height);
}
This of-course works fine on iOS...
The only reason why I am trying to embed a Page rather than a View is that the call to Platform.CreateRenderer
always returns an unitialized view as it is not in the parent page's Visual Tree.