0

我正在尝试测试 Lens 应用程序功能,在CameraCaptureTask用户从 LensPicker 选择应用程序后,我的应用程序应该直接导航到该功能(因为我的 MainPage 上没有取景器)。返回 MainPage 后,CamerCaptureTask有一个完成的事件,它将在屏幕上显示图像。

我遇到了一个奇怪的反复出现的情况的问题,根据我在应用程序被墓碑之前无法清除CameraCaptureTask的值的结果重复调用我,然后在完成后重新启动。QueryStringCameraCaptureTask

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
        }
    }
}

如何清除该值,以便我的应用程序在完成后QueryString不会继续调用并且应用程序继续运行?newButton_Click(null, null)CameraCaptureTask

4

2 回答 2

0

在 MainPage 的 OnNavigatedTo 中,使用 NavigationMode 来查找您是否从 CameraCaptureTask 返回

protected override void OnNavigatedTo(NavigationEventArgs e)
{
     if(e.NavigationMode == NavigationMode.Back)
         return;

     // else continue further with CameraCaptureTask
}

或者

protected override void OnNavigatedTo(NavigationEventArgs e)
{
     if(e.NavigationMode == NavigationMode.New)
         // continue further with CameraCaptureTask
}
于 2013-10-16T08:29:55.733 回答
0
string fromLensPicker = null;
if (NavigationContext.QueryString.TryGetValue("fromLensPicker", out fromLensPicker))
{
    if (fromLensPicker == "fromLensPicker")
    {
        NavigationContext.QueryString.Remove("fromLensPicker");
        //...
    }
}
于 2013-10-16T17:19:02.920 回答