如何创建像 CameraCaptureUI.CaptureFileAsync 这样的对话框? [英] How to create a dialog like CameraCaptureUI.CaptureFileAsync?
问题描述
我想创建一个类似于 CaptureFileAsync 方法,即在调用方法时,它会打开一个带有标准返回导航的全屏页面,并将结果返回给调用者.
我希望能够像调用 CaptureFileAsync 一样调用它:
var dialog = new Library.Dialog();var result = await dialog.Show();
在 Show
方法中,我当前导航到我自己的页面并返回一个 Task
可以由调用者等待:
public Task展示(){var task = new Task(() => result);var frame = ((Window.Current.Content) as Frame);frame.Navigate(typeof(DialogPage));返回任务;}
我在关闭对话框时调用 task.Start()
(通过向后导航取消或按下按钮确认)导致结果返回给等待的调用者.>
问题在于,当调用Frame.GoBack()
时,会创建上一页的新实例,并将结果返回到不再显示的旧实例.这不是 CaptureFileAsync
的工作方式:在这种情况下,会保留调用页面的相同实例.
我的问题是:如何在不影响框架导航和无意中创建调用页面的新实例的情况下显示库中的页面?
您可以将所有 UI 放在一个弹出窗口中.
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?
You can put all your UI on a Popup.
这篇关于如何创建像 CameraCaptureUI.CaptureFileAsync 这样的对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!