PhotoChooserTask + Navigation.

Posted by user562405 on Stack Overflow See other posts from Stack Overflow or by user562405
Published on 2011-01-14T11:48:19Z Indexed on 2011/01/14 11:54 UTC
Read the original article Hit count: 238

Filed under:

I taken two Images & added event (MouseButtonDown) for them. When first image handles event to open Gallery. Second image handles events for open camera. When user has choosed his image from the gallery, I want to navigate to next page. Its navigates. But before completing navigation process, it displays MainPage & then moves toward next page. I didnt want to display the MainPage once user chooses the image from the gallery. Plz help. Thanks in advance.

public partial class MainPage : PhoneApplicationPage

{
    PhotoChooserTask objPhotoChooser;
    CameraCaptureTask cameraCaptureTask;

    // Constructor
    public MainPage()
    {
        InitializeComponent();

        objPhotoChooser = new PhotoChooserTask();
        objPhotoChooser.Completed += new EventHandler<PhotoResult>(objPhotoChooser_Completed);

        cameraCaptureTask = new CameraCaptureTask();
        cameraCaptureTask.Completed += new EventHandler<PhotoResult>(objCameraCapture_Completed);         
    }

    void objPhotoChooser_Completed(object sender, PhotoResult e)
    {
        if (e != null && e.TaskResult == TaskResult.OK)
        {
            //Take JPEG stream and decode into a WriteableBitmap object                
            App.CapturedImage = PictureDecoder.DecodeJpeg(e.ChosenPhoto);

            //Delay navigation until the first navigated event
            NavigationService.Navigated += new NavigatedEventHandler(navigateCompleted);
        }
    }


    void navigateCompleted(object sender, EventArgs e)
    {
        //Do the delayed navigation from the main page
        this.NavigationService.Navigate(new Uri("/ImageViewer.xaml", UriKind.RelativeOrAbsolute));
        NavigationService.Navigated -= new NavigatedEventHandler(navigateCompleted);
    }


    void objCameraCapture_Completed(object sender, PhotoResult e)
    {
        if (e.TaskResult == TaskResult.OK)
        {
            //Take JPEG stream and decode into a WriteableBitmap object                
            App.CapturedImage = PictureDecoder.DecodeJpeg(e.ChosenPhoto);

            //Delay navigation until the first navigated event
            NavigationService.Navigated += new NavigatedEventHandler(navigateCompleted);          
        }
    }


    protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
    {
        e.Cancel = true;
    }


    private void image1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        objPhotoChooser.Show();
    }


    private void image2_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        cameraCaptureTask.Show();
    }

© Stack Overflow or respective owner

Related posts about windows-phone-7