导航到Windows Phone 8镜头应用程序中的按钮单击事件

时间:2013-08-27 03:07:34

标签: c# windows-phone-8

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

App.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的镜头应用指南中的说明,如何按后退键直接导航回默认的相机应用程序?

1 个答案:

答案 0 :(得分: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);
}