none
使用PickSingleFileAndContinue问题 RRS feed

  • 问题

  • 我使用了PickSingleFileAndContinue打开一个zip文件,但是当我连续打开两次文件(无论其是否一样,或者其中一次我并没有选择文件直接返回),都会弹出exception提示“can't set args more than once"。我使用的是微软官方提供的ContinuationManager的代码,弹出exception的代码如下

    internal void Continue(IContinuationActivatedEventArgs args, Frame rootFrame) { if (args == null) throw new ArgumentNullException("args"); if (this.args != null && !handled) throw new InvalidOperationException("Can't set args more than once"); this.args = args; this.handled = false; this.id = Guid.NewGuid(); if (rootFrame == null) return; switch (args.Kind) { case ActivationKind.PickFileContinuation: var fileOpenPickerPage = rootFrame.Content as IFileOpenPickerContinuable; if (fileOpenPickerPage != null) { fileOpenPickerPage.ContinueFileOpenPicker(args as FileOpenPickerContinuationEventArgs); } break; case ActivationKind.PickSaveFileContinuation: var fileSavePickerPage = rootFrame.Content as IFileSavePickerContinuable; if (fileSavePickerPage != null) { fileSavePickerPage.ContinueFileSavePicker(args as FileSavePickerContinuationEventArgs); } break; case ActivationKind.PickFolderContinuation: var folderPickerPage = rootFrame.Content as IFolderPickerContinuable; if (folderPickerPage != null) { folderPickerPage.ContinueFolderPicker(args as FolderPickerContinuationEventArgs); } break; case ActivationKind.WebAuthenticationBrokerContinuation: var wabPage = rootFrame.Content as IWebAuthenticationContinuable; if (wabPage != null) { wabPage.ContinueWebAuthentication(args as WebAuthenticationBrokerContinuationEventArgs); } break; } }

    但是我参考过 sample里面的 file pick sample,发现里面并没有出现一样的问题,但是我和sample里面的代码基本是一样的。

    private void Button_open(object sender, RoutedEventArgs e)
            {
               
                FileOpenPicker openPicker = new FileOpenPicker();
                openPicker.ViewMode = PickerViewMode.Thumbnail;
                openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
                openPicker.FileTypeFilter.Add(".zip");
                //op.ContinuationData["FileSelect"] = "Picture";
                openPicker.PickSingleFileAndContinue();
    
            }
    
            // called after a file has been picked
            public void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args)
            {
                if (args.Files.Count > 0)
                {
                    StorageFile file = args.Files[0];
                    UnZipFiles(file);
                }
            }

    唯一的不同是,sample里面点击了打开文件的按钮之后可以直接进入图片文件夹,但是我还要先选onedrive或者是手机。

    求解答!

    2014年10月11日 8:33

全部回复