亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

用于閱讀 pdf 的自定義 Xamarin.Forms.WebView。用錨滾動

用于閱讀 pdf 的自定義 Xamarin.Forms.WebView。用錨滾動

C#
米琪卡哇伊 2021-06-30 17:02:21
我嘗試找到在 xamarin.forms 上顯示本地 pdf 文件的方法。我找到了一個實現 webview 及其渲染的自定義實現的解決方案:pdf 閱讀器主要代碼是:public class CustomWebView : WebView{    public static readonly BindableProperty UriProperty = BindableProperty.Create<CustomWebView, string>(p => p.Uri, default(string));    public string Uri    {        get { return (string)GetValue(UriProperty); }        set { SetValue(UriProperty, value); }    }}使成為:[assembly: ExportRenderer (typeof(CustomWebView), typeof(CustomWebViewRenderer))]namespace DisplayPDF.iOS{    public class CustomWebViewRenderer : ViewRenderer<CustomWebView, UIWebView>    {        protected override void OnElementChanged (ElementChangedEventArgs<CustomWebView> e)        {            base.OnElementChanged (e);            if (Control == null) {                SetNativeControl (new UIWebView ());            }            if (e.OldElement != null) {                // Cleanup            }            if (e.NewElement != null) {                var customWebView = Element as CustomWebView;                string fileName = Path.Combine (NSBundle.MainBundle.BundlePath, string.Format ("Content/{0}", WebUtility.UrlEncode (customWebView.Uri)));                Control.LoadRequest (new NSUrlRequest (new NSUrl (fileName, false)));                Control.ScalesPageToFit = true;            }        }    }}還有我的頁面:public class WebViewPageCS : ContentPage    {        public WebViewPageCS ()        {            webView = new CustomWebView            {                Uri = "ScalaReference.pdf",                HorizontalOptions = LayoutOptions.FillAndExpand,                VerticalOptions = LayoutOptions.FillAndExpand            };    }但是現在我找不到像這篇文章中描述的那樣向這個 pdf 文件添加錨點的方法:anchor to pdf我還嘗試將此代碼用于評估腳本:private async void Scroll_Clicked(object sender, EventArgs e){      webView.Eval($"window.scrollTo(0, {x});");}它適用于默認 webview,但不適用于自定義 webview。也許有人知道通過 xamarin.forms 將錨點滾動/設置為 pdf 并鏈接到該錨點的任何其他方法?謝謝你。
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 142 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號