C# 如何删除查询字符串值以避免逻辑删除问题
我正在尝试测试镜头应用程序功能,其中我的应用程序应该在用户从LensPicker选择应用程序后直接导航到C# 如何删除查询字符串值以避免逻辑删除问题,c#,windows-phone-8,C#,Windows Phone 8,我正在尝试测试镜头应用程序功能,其中我的应用程序应该在用户从LensPicker选择应用程序后直接导航到CameraCaptureTask(因为我的主页上没有取景器)。返回主页面后,CamerCaptureTask有一个已完成的事件,该事件将在屏幕上显示图像 我遇到了一个奇怪的反复出现的问题,根据QueryString值的结果重复调用我的CameraCaptureTask,在应用程序被删除之前,我无法清除该值,然后在CameraCaptureTask完成后重新启动 LensExampleUriM
CameraCaptureTask
(因为我的主页上没有取景器)。返回主页面后,CamerCaptureTask
有一个已完成的事件,该事件将在屏幕上显示图像
我遇到了一个奇怪的反复出现的问题,根据QueryString
值的结果重复调用我的CameraCaptureTask
,在应用程序被删除之前,我无法清除该值,然后在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
}
}
}
如何清除
QueryString
值,使我的应用程序在CameraCaptureTask
完成且应用程序继续后不会连续调用newButton\u单击(null,null)
。在主页的OnNavigatedTo中,使用导航模式查找是否从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
}
string fromLensPicker = null;
if (NavigationContext.QueryString.TryGetValue("fromLensPicker", out fromLensPicker))
{
if (fromLensPicker == "fromLensPicker")
{
NavigationContext.QueryString.Remove("fromLensPicker");
//...
}
}