问题描述
我正在研究Xamarin Forms-UWP.我想在webview控件中显示本地PDF文件.我关注了这两个链接: https://developer.xamarin.com/recipes/cross-platform/xamarin-forms/controls/display-pdf/
I am working on Xamarin Forms - UWP.I want to display local PDF file in webview control. I followed these 2 links :-https://developer.xamarin.com/recipes/cross-platform/xamarin-forms/controls/display-pdf/
它将打开pdf文件,但内容均为空白.有人可以帮我解决我可能会想念的东西吗?
It opens the pdf file but content is all blank.Can anyone please help me in what I may be missing?
提前谢谢!
这是我的代码:-CustomWebView.cs
Here is my code:-CustomWebView.cs
public class CustomWebView : WebView
{
public static readonly BindableProperty UriProperty = BindableProperty.Create(propertyName: "Uri",
returnType: typeof(string),
declaringType: typeof(CustomWebView),
defaultValue: default(string));
public string Uri
{
get { return (string)GetValue(UriProperty); }
set { SetValue(UriProperty, value); }
}
}
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:PdfViewer;assembly=PdfViewer"
x:Class="PdfViewer.MainPage"
Padding="0,20,0,0">
<ContentPage.Content>
<local:CustomWebView Uri="samplepdf.pdf" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
</ContentPage.Content>
[assembly: ExportRenderer(typeof(PdfViewer.CustomWebView), typeof(CustomWebViewRenderer))]
namespace PdfViewer.UWP
{
public class CustomWebViewRenderer : WebViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
var customWebView = Element as CustomWebView;
Control.Source = new Uri(string.Format("ms-appx-web:///Assets/pdfjs/web/viewer.html?file={0}", string.Format("ms-appx-web:///Assets/Content/{0}", WebUtility.UrlEncode(customWebView.Uri))));
}
}
}
}
推荐答案
资产文件夹文件好像发生了一些事情.从nuget存储库更新时,它可以正常工作.
Looks like something happened with Asset folder files. When was updated from nuget repository it worked.
这篇关于在Webview控件中显示本地PDF文件-显示空白的Pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!