简体   繁体   中英

Windows Phone 8.1 file open picker page navigation error

private void Gallery_Click(object sender, object e)
{
    view = CoreApplication.GetCurrentView();
    var filePicker = new FileOpenPicker
    {
        SuggestedStartLocation = PickerLocationId.PicturesLibrary,
        ViewMode = PickerViewMode.Thumbnail
    };

    // Filter to include a sample subset of file types
    filePicker.FileTypeFilter.Clear();
    filePicker.FileTypeFilter.Add(".bmp");
    filePicker.FileTypeFilter.Add(".png");
    filePicker.FileTypeFilter.Add(".jpeg");
    filePicker.FileTypeFilter.Add(".jpg");

    mediaCapture.StopPreviewAsync();

    filePicker.PickSingleFileAndContinue();
    view.Activated += ViewActivated;
}

private async void ViewActivated(CoreApplicationView sender, IActivatedEventArgs args)
{
    var arguments = args as FileOpenPickerContinuationEventArgs;

    if (arguments != null && arguments.Files.Count != 0)
    {
        view.Activated -= ViewActivated;
        var storageFile = arguments.Files[0];

        var file =
            await
                ApplicationData.Current.LocalFolder.CreateFileAsync("Photo.jpg",
                    CreationCollisionOption.GenerateUniqueName);
        await storageFile.CopyAndReplaceAsync(file);

        var bmpImage = new BitmapImage(new Uri(file.Path));

        UseThePhoto(bmpImage);                
    }
    else
        await mediaCapture.StartPreviewAsync();

}

I have this code above. When I choose an image from a gallery I can use it in an Image control that is on the same page. However, if I want to navigate to any other page, I get an error. No details from it. The code ends in App.gics

Problem solved. I was using not the blank page template but the basic page. And for some reason the method OnNavigatedFrom invoked this error so i created an override and let it empty, so it couldn't call the navigation helper class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM