在模拟器中打开PDF文件

时间:2014-02-25 10:26:28

标签: c# wpf pdf windows-phone-8 windows-phone

我有这段代码:

private async void LaunchPDF(string name) 
        {
            var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(name);

            if (file != null)
            {
                // Set the option to show the picker
                var options = new Windows.System.LauncherOptions();
                options.DisplayApplicationPicker = true;

                // Launch the retrieved file
                bool success = await Windows.System.Launcher.LaunchFileAsync(file, options);
                if (success)
                {
                    // File launched
                    Debug.WriteLine("File Launched");
                }
                else
                {
                    // File launch failed
                    Debug.WriteLine("File Launched Failed");
                }
            }
            else
            {
                // Could not find file
                Debug.WriteLine("File not found");
            }
        }

此方法在此处调用:

private void longListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            MyObject item  =  longListSelector.SelectedItem as MyObject;
            LaunchPDF("Data/PDF/" + item.SubTitle + ".pdf");
        }

我在Windows Phone 8 Emulator进行测试,当我点击长列表选择器中的项目时,我得到以下错误:

{System.ArgumentException: Value does not fall within the expected range.
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at MyApp.Classes.Views.PDFPage.<LaunchPDF>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__0(Object state)}

如何解决这个问题?我在这做错了什么?

修改

我也设置了这个,改变了它的构建动作。

右键点击PDF文档。

点击属性。

将构建操作从无更改为内容

0 个答案:

没有答案