Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Navigate to CameraCaptureTask from LensPicker
    text
    copied!<p>I have created a small sample Lens application, and I would like to be able to directly navigate to the CameraCaptureTask when the Lens icon is clicked in the default camera application. In my application I am already calling the CameraCaptureTask within a button click event during normal app operations. How might I set this up to work as well from the LensPicker option?</p> <p>I have been referencing <a href="http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj662936(v=vs.105).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj662936(v=vs.105).aspx</a></p> <p>LensExampleUriMapper.cs</p> <pre><code>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; } </code></pre> <p>I was thinking of passing a QueryString value in <code>return new Uri("/MainPage.xaml", UriKind.Relative);</code> so that in my MainPage <code>OnNavigatedTo</code> event I could check that QueryString value and call the CameraCaptureTask, and then just route the result to the already existing event handler I have created (which displays the resulting image in MainPage). For some reason I am getting a debugging error when trying to create the QueryString to pass, and I am unsure of why? </p> <p>EDIT** No longer getting error, but an infinite loop occurs when calling CameraCaptureTask. Why?</p> <p>LensExampleUriMapper.cs</p> <pre><code>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; } </code></pre> <p>MainPage.xaml.cs</p> <pre><code>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 } } } </code></pre> <p>I believe that when <code>CameraCaptureTask</code> is called, the application is tombstoned and then resumed on MainPage, in which the <code>QueryString</code> value <code>fromLensPicker == "fromLensPicker"</code> and the entire cycle starts over again, repetitively. How might I solve this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload