I would like to create a library behaving like the CaptureFileAsync method, i.e. on a method call it would open up a full screen page with standard back navigation and return result to the caller.
I want to be able to call it the same way CaptureFileAsync is called:
var dialog = new Library.Dialog();
var result = await dialog.Show();
In the Show
method I'm currently navigating to my own page and returning a Task
which can be awaited by the caller:
public Task<string> Show()
{
var task = new Task<string>(() => result);
var frame = ((Window.Current.Content) as Frame);
frame.Navigate(typeof(DialogPage));
return task;
}
I call task.Start()
when the dialog is being closed (either cancelled by navigating back or confirmed by pressing a button) which causes the result to be returned to the awaiting caller.
The problem is that when Frame.GoBack()
is called, a new instance of the previous page is created and the result gets returned to the old instance which is not displayed any more. This is not how CaptureFileAsync
works: in its case the same instance of the calling page is kept.
My question is: how can I display a page from my library without affecting the frame navigation and inadvertently causing a new instance of the calling page to be created?
I had the same issue, and this is what I came up with:
XAML
The Control
Usage
You can put all your UI on a Popup.
Take a look at PopupHelper.
It abstracts all the ickines of using Popups and takes care of animation, disabling access to controls etc.