我创建了一个小的示例镜头应用程序,我希望能够在默认相机应用程序中单击镜头图标时直接导航到 CameraCaptureTask。在我的应用程序中,我已经在正常的应用程序操作期间在按钮单击事件中调用了 CameraCaptureTask。我怎样才能通过 LensPicker 选项设置它以使其正常工作?
我一直在参考 http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj662936(v=vs.105).aspx
LensExampleUriMapper.cs
private string tempUri;
public override Uri MapUri(Uri uri)
{
tempUri = uri.ToString();
// Look for a URI from the lens picker.
if (tempUri.Contains("ViewfinderLaunch"))
{
// Launch as a lens, launch viewfinder screen.
return new Uri("/MainPage.xaml", UriKind.Relative);
}
// Otherwise perform normal launch.
return uri;
}
我正在考虑传入一个 QueryString 值,return new Uri("/MainPage.xaml", UriKind.Relative);
以便在 MainPageOnNavigatedTo
事件中检查该 QueryString 值并调用 CameraCaptureTask,然后将结果路由到我创建的现有事件处理程序(在 MainPage 中显示结果图像) . 出于某种原因,我在尝试创建要传递的 QueryString 时遇到调试错误,我不确定为什么?
编辑** 不再出现错误,但调用 CameraCaptureTask 时会发生无限循环。为什么?
LensExampleUriMapper.cs
private string tempUri;
public override Uri MapUri(Uri uri)
{
tempUri = uri.ToString();
// Look for a URI from the lens picker.
if (tempUri.Contains("ViewfinderLaunch"))
{
// Launch as a lens, launch viewfinder screen.
return new Uri("/MainPage.xaml?fromLensPicker=" + "fromLensPicker", UriKind.Relative);
}
// Otherwise perform normal launch.
return uri;
}
MainPage.xaml.cs
protected override void OnNavigatedTo(NavigationEventArgs e)
{
string fromLensPicker = null;
if (NavigationContext.QueryString.TryGetValue("fromLensPicker", out fromLensPicker))
{
if (fromLensPicker == "fromLensPicker")
{
newButton_Click(null, null); //click event that calls CameraCaptureTask
fromLensPicker = null; //Temporarily nullifies value until MainPage is OnNavigatedTo after CameraCaptureTask completes
}
}
}
我相信,当CameraCaptureTask
被调用时,应用程序会被删除,然后在 MainPage 上恢复,其中QueryString
值fromLensPicker == "fromLensPicker"
和整个循环会重复地重新开始。我该如何解决这个问题?