private FileOpenPicker CreateFileOpenPicker(FilePickerServiceOptions options)
        {
            var fileOpenPicker = new FileOpenPicker
            {
                SuggestedStartLocation = options.SuggestedStartLocation.ToPickerLocationId(),
                ViewMode = options.ViewMode.ToPickerViewMode()
            };

            if (options.FileTypeFilters != null)
            {
                foreach (var fileTypeFilter in options.FileTypeFilters)
                {
                    fileOpenPicker.FileTypeFilter.Add(fileTypeFilter);
                }
            }

            return(fileOpenPicker);
        }
        /// <summary>
        /// Shows the file picker so that the user can pick one file.
        /// </summary>
        /// <param name="options">The options.</param>
        /// <returns>The <see cref="Task"/> object representing the asynchronous operation.</returns>
        public virtual async Task <FilePickerServiceFileResult> PickSingleFileAsync(FilePickerServiceOptions options)
        {
            var filePicker = CreateFileOpenPicker(options);

#if WINDOWS_PHONE_81 || WINDOWS_PHONE_APP
            var coreApplicationView  = CoreApplication.GetCurrentView();
            var taskCompletionSource = new TaskCompletionSource <StorageFile>();

            TypedEventHandler <CoreApplicationView, IActivatedEventArgs> handler = null;

            handler = (sender, e) =>
            {
                coreApplicationView.Activated -= handler;

                var fileOpenPickerContinuationEventArgs = e as FileOpenPickerContinuationEventArgs;

                if (fileOpenPickerContinuationEventArgs != null &&
                    fileOpenPickerContinuationEventArgs.Kind == ActivationKind.PickFileContinuation &&
                    fileOpenPickerContinuationEventArgs.Files != null)
                {
                    taskCompletionSource.SetResult(fileOpenPickerContinuationEventArgs.Files.FirstOrDefault());
                }
                else
                {
                    taskCompletionSource.SetResult(null);
                }
            };

            coreApplicationView.Activated += handler;

            filePicker.PickSingleFileAndContinue();

            var selectedFile = await taskCompletionSource.Task.ConfigureAwait(false);
#else
            var selectedFile = await filePicker.PickSingleFileAsync();
#endif

            if (selectedFile != null)
            {
                return(new FilePickerServiceFileResult(selectedFile));
            }

            return(null);
        }
        /// <summary>
        /// Shows the file picker so that the user can pick one file.
        /// </summary>
        /// <param name="options">The options.</param>
        /// <returns>The <see cref="Task"/> object representing the asynchronous operation.</returns>
        public virtual async Task<FilePickerServiceFileResult> PickSingleFileAsync(FilePickerServiceOptions options)
        {
            var filePicker = CreateFileOpenPicker(options);

#if WINDOWS_PHONE_81 || WINDOWS_PHONE_APP
            var coreApplicationView = CoreApplication.GetCurrentView();
            var taskCompletionSource = new TaskCompletionSource<StorageFile>();

            TypedEventHandler<CoreApplicationView, IActivatedEventArgs> handler = null;

            handler = (sender, e) =>
            {
                coreApplicationView.Activated -= handler;

                var fileOpenPickerContinuationEventArgs = e as FileOpenPickerContinuationEventArgs;

                if (fileOpenPickerContinuationEventArgs != null &&
                    fileOpenPickerContinuationEventArgs.Kind == ActivationKind.PickFileContinuation &&
                    fileOpenPickerContinuationEventArgs.Files != null)
                {
                    taskCompletionSource.SetResult(fileOpenPickerContinuationEventArgs.Files.FirstOrDefault());
                }
                else
                {
                    taskCompletionSource.SetResult(null);
                }
            };

            coreApplicationView.Activated += handler;

            filePicker.PickSingleFileAndContinue();

            var selectedFile = await taskCompletionSource.Task.ConfigureAwait(false);
#else
            var selectedFile = await filePicker.PickSingleFileAsync();
#endif

            if (selectedFile != null)
            {
                return new FilePickerServiceFileResult(selectedFile);
            }

            return null;
        }
 /// <summary>
 /// Shows the file picker so that the user can pick multiple files.
 /// </summary>
 /// <param name="options">The options.</param>
 /// <returns>The <see cref="Task"/> object representing the asynchronous operation.</returns>
 public virtual Task<IEnumerable<FilePickerServiceFileResult>> PickMultipleFilesAsync(FilePickerServiceOptions options)
 {
     return ExceptionHelper.ThrowNotSupported<Task<IEnumerable<FilePickerServiceFileResult>>>();
 }
 /// <summary>
 /// Shows the file picker so that the user can pick one file.
 /// </summary>
 /// <param name="options">The options.</param>
 /// <returns>The <see cref="Task"/> object representing the asynchronous operation.</returns>
 public virtual Task<FilePickerServiceFileResult> PickSingleFileAsync(FilePickerServiceOptions options)
 {
     return ExceptionHelper.ThrowNotSupported<Task<FilePickerServiceFileResult>>();
 }
        private FileOpenPicker CreateFileOpenPicker(FilePickerServiceOptions options)
        {
            var fileOpenPicker = new FileOpenPicker
            {
                SuggestedStartLocation = options.SuggestedStartLocation.ToPickerLocationId(),
                ViewMode = options.ViewMode.ToPickerViewMode()
            };

            if (options.FileTypeFilters != null)
            {
                foreach (var fileTypeFilter in options.FileTypeFilters)
                {
                    fileOpenPicker.FileTypeFilter.Add(fileTypeFilter);
                }
            }

            return fileOpenPicker;
        }
 /// <summary>
 /// Shows the file picker so that the user can pick multiple files.
 /// </summary>
 /// <param name="options">The options.</param>
 /// <returns>The <see cref="Task"/> object representing the asynchronous operation.</returns>
 public virtual Task <IEnumerable <FilePickerServiceFileResult> > PickMultipleFilesAsync(FilePickerServiceOptions options)
 {
     return(ExceptionHelper.ThrowNotSupported <Task <IEnumerable <FilePickerServiceFileResult> > >());
 }
 /// <summary>
 /// Shows the file picker so that the user can pick one file.
 /// </summary>
 /// <param name="options">The options.</param>
 /// <returns>The <see cref="Task"/> object representing the asynchronous operation.</returns>
 public virtual Task <FilePickerServiceFileResult> PickSingleFileAsync(FilePickerServiceOptions options)
 {
     return(ExceptionHelper.ThrowNotSupported <Task <FilePickerServiceFileResult> >());
 }