1

在 Windows Phone 上的默认相机应用程序中按下我的应用程序的镜头磁贴图标后,我想导航到我的应用程序。我有这个工作,虽然我使用 CameraCaptureTask 拍照,然后我保存并在我的 MainPage 中显示它们。我在单击事件上调用 CameraCaptureTask,所以我的问题是当我在镜头选择器中选择应用程序磁贴时如何访问此单击事件?

应用程序.xaml.cs

private void InitializePhoneApplication()
    {
        if (phoneApplicationInitialized)
            return;

        // Create the frame but don't set it as RootVisual yet; this allows the splash
        // screen to remain active until the application is ready to render.
        //RootFrame = new PhoneApplicationFrame();
        RootFrame = new TransitionFrame();
        RootFrame.Navigated += CompleteInitializePhoneApplication;

        // Assign the lens example URI-mapper class to the application frame.
        RootFrame.UriMapper = new LensUriMapper();

        // Handle navigation failures
        RootFrame.NavigationFailed += RootFrame_NavigationFailed;

        // Handle reset requests for clearing the backstack
        RootFrame.Navigated += CheckForResetNavigation;

        // Ensure we don't initialize again
        phoneApplicationInitialized = true;
    }

LensUriMapper.cs

class LensUriMapper : UriMapperBase
{
    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("/Views/MainPage.xaml", UriKind.Relative);
            return new Uri("/Views/MainPage.xaml?Viewfinder=1", UriKind.Relative);
        }
        }

        // Otherwise perform normal launch.
        return uri;
    }
}

MainPage.xaml.cs

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    if (NavigationContext.QueryString.ContainsKey("Viewfinder"))
    {
        newButton_Click(null, null);
    }
}

void newButton_Click(object sender, EventArgs e)
    {            
        _cameraTask.Show();
    }

此外,如 MSDN 的镜头应用程序指南中所述,我如何在按下后退键时直接导航回默认相机应用程序?

4

1 回答 1

0

您可以向 ViewfinderLaunch uri 添加一个参数:

return new Uri("/Views/MainPage.xaml?Viewfinder=1", UriKind.Relative);

接下来,您必须覆盖 MainPage 的“OnNavigatedTo”方法以检查是否设置了 Viewfinder 参数:

if (NavigationContext.QueryString.ContainsKey("Viewfinder"))
{
    newButton_Click(null, null);
}
于 2013-08-29T03:30:26.610 回答