0

我正在开发一个 wp8 应用程序,它会拍一张照片,然后带你到下一个屏幕来决定你是否喜欢它。目前的做法是这样的:

private void ShutterButton_Click(object sender, RoutedEventArgs e)
{
    if (cam != null)
    {
        try
        {
            cam.CaptureImage();

            await Task.Delay(1500);
            NavigateFront();
        }
        catch (Exception ex)
        {
            ...
        }
    }
}

public void NavigateFront()
{
    string naviString = "/confirmPicture.xaml?parameter=" + fileName.ToString();   
    _rootFrame.Navigate(new Uri(naviString, UriKind.Relative));
}

在我的 Lumia 520 上,它有时会崩溃。如果我将等待时间增加到 2.5 秒,它会起作用。但当然这不应该是这样做的方式。

如果我捕捉到void cam_CaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e)-Event 并在一切完成并且所有流都关闭后尝试导航,我仍然会进入NavigateFailed-State 并且应用程序崩溃。

我的问题是:是否有任何其他有用的事件可以确保完成所有工作并且我可以在不使用基于时间的静态值的情况下进行导航?

4

1 回答 1

1

可以使用 PhotoCamera 进行导航,只需订阅其 CaptureCompleted 事件处理程序

cam.CaptureCompleted += new EventHandler<CameraOperationCompletedEventArgs>(camera_CaptureCompleted);

这将是事件

    void camera_CaptureCompleted(object sender, CameraOperationCompletedEventArgs e)
    {
        try
        {
            Deployment.Current.Dispatcher.BeginInvoke(delegate()
            {
                try
                {
                    cam.Dispose();
                    NavigationService.Navigate(new Uri("URI nething", UriKind.Relative));
                }
                catch (Exception)
                {

                     MessageBox.Show("Problem occured!!");
                }

            });
        }
        catch
        {
            MessageBox.Show("Problem in camer_capturecompleted");
        }
    }

我在我的一个针对 windows phone 7 的应用程序中做到了。检查这是否也适用于你。

于 2014-03-12T07:52:29.723 回答