【问题标题】:Navigate to Button Click Event in Lens Application for Windows Phone 8导航到 Windows Phone 8 镜头应用程序中的按钮单击事件
【发布时间】:2013-08-27 03:07:34
【问题描述】:

在 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 的镜头应用指南中所述,我如何在按下后退键时直接导航回默认相机应用程序?

【问题讨论】:

    标签: c# windows-phone-8


    【解决方案1】:

    您可以向 ViewfinderLaunch uri 添加参数:

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

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

    if (NavigationContext.QueryString.ContainsKey("Viewfinder"))
    {
        newButton_Click(null, null);
    }
    

    【讨论】:

    • 我尝试了您的解决方案,但由于某种原因,调试器在没有任何错误消息的情况下中断。我编辑了上面的代码以反映我的更改。
    • 我相信它在设置return new Uri("/Views/MainPage.xaml?Viewfinder=1", UriKind.Relative);时或之后会中断
    猜你喜欢
    • 2012-12-16
    • 1970-01-01
    • 1970-01-01
    • 2014-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多