如何删除QueryString值以避免墓碑问题

时间:2013-10-16 04:21:34

标签: c# windows-phone-8

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

我遇到一个奇怪的重复出现的问题,我的CameraCaptureTask会根据QueryString值的结果重复调用,在应用程序被逻辑删除之后我无法清除,然后在{{{{}}之后重新启动1}}完成。

LensExampleUriMapper.cs

CameraCaptureTask

MainPage.xaml.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;
}

如何清除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)

2 个答案:

答案 0 :(得分:0)

在OnNavigatedTo of MainPage中使用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
}

答案 1 :(得分:0)

string fromLensPicker = null;
if (NavigationContext.QueryString.TryGetValue("fromLensPicker", out fromLensPicker))
{
    if (fromLensPicker == "fromLensPicker")
    {
        NavigationContext.QueryString.Remove("fromLensPicker");
        //...
    }
}