The overall goal of what you are trying to achieve can be achieved using the PushModalAsync and PopModalAsync methods of Xamarin.Forms Navigation .
Most likely, this is good enough for what you need - however - it is not entirely modal. I will explain after a small piece of code: -
StackLayout objStackLayout = new StackLayout() { }; // Button cmdButton_LaunchModalPage = new Button(); cmdButton_LaunchModalPage.Text = "Launch Modal Window"; objStackLayout.Children.Add(cmdButton_LaunchModalPage); // cmdButton_LaunchModalPage.Clicked += (async (o2, e2) => { ContentPage objModalPage = new ContentPage(); objModalPage.Content = await CreatePageContent_Page2(); // await Navigation.PushModalAsync(objModalPage); // // Code will get executed immediately here before the page is dismissed above. }); // return objStackLayout; private async Task<StackLayout> CreatePageContent_Page2() { StackLayout objStackLayout = new StackLayout() { }; // Button cmdButton_CloseModalPage = new Button(); cmdButton_CloseModalPage.Text = "Close"; objStackLayout.Children.Add(cmdButton_CloseModalPage); // cmdButton_CloseModalPage.Clicked += ((o2, e2) => { this.Navigation.PopModalAsync(); }); // return objStackLayout; }
The problem with the above is that
await Navigation.PushModalAsync(objModalPage);
will return immediately after the animation.
Although you cannot interact with the previous page, since we are showing a new NavigationPage with the Close button displayed - the parent Navigation Page is still running behind the scenes in parallel.
So, if you have any timers or something that they executed, they will still be called if you don't stop them.
You can also use the TaskCompletionSource approach, as indicated in the next post, as well How can I expect modal form rejection using Xamarin.Forms? .
Note that although you can now wait for the 2nd page to be displayed, and then when this page is missed to continue executing the code on the next line, this is still not a true modal form . Again, timers or something else will be called on the parent page.
Update 1: -
To display content on top of existing content, simply add it to the current page, however, make this section of the content invisible until you need it.
If you use an external container, such as a Grid , that supports multiple child controls in the same cell, you can achieve what you want.
You will also want to use something like a filled Box with transparency, which will also cover the entire page to control the visible, viewable section that surrounds your internal content section.