本文介绍了在Windows Phone 8推出的PDF阅读器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我试图推出PDF阅读器与下面的代码,但它不工作。 ?有人可以帮我。I'm trying to launch pdf reader with the code below but it does not work. Can somebody help me? private async Task<StorageFile> WriteData(string fileName, byte[] data) { StorageFolder folder = ApplicationData.Current.LocalFolder; StorageFile file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting); using (Stream s = await file.OpenStreamForWriteAsync()) { await s.WriteAsync(data, 0, data.Length); s.Close(); } return file; } private async Task<bool> OpenPdf(StorageFile file) { var uri = new Uri(file.Path, UriKind.RelativeOrAbsolute); bool result = await Windows.System.Launcher.LaunchUriAsync(uri); return result; } private async void FetchPdf() { // Fetch pdf bytes to network //.... StorageFile file = await WriteData("test.pdf", data); if (file != null) { bool result = await OpenPdf(file); if (result) Debug.WriteLine("Success"); else Debug.WriteLine("Cannot open pdf file."); } } 结果始终是假的,因此发射不会出现。result is always false and so launcher is not presented.我用LaunchUriAsync因为LaunchFileAsync不是Windows Phone上实现的。I used LaunchUriAsync because LaunchFileAsync is not implemented on Windows Phone.推荐答案 LaunchUriAsync 不支持在Windows Phone 8%的文档。这将引发称为异常LaunchUriAsync isn't supported on Windows Phone 8 per the documentation. It throws an exception if called您可以使用 Windows.System.Launcher.LaunchFileAsync 推出 StorageFile 。这代码的工作,例如(assming有一个名为metro.pdf文件项目,以生成操作设置为内容与复制到输出目录设置为复制如果较新的)。This code works for example (assming there's a file called "metro.pdf" in the project, with the Build Action set to Content, with Copy to Output Directory set to Copy if Newer).var installedLocation = Windows.ApplicationModel.Package.Current.InstalledLocation;var assets = await installedLocation.GetFolderAsync("Assets");var pdf = await assets.GetFileAsync("metro.pdf");Windows.System.Launcher.LaunchFileAsync(pdf); 这篇关于在Windows Phone 8推出的PDF阅读器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-29 21:21