Xamarin Forms - 将 GIF 存储到 WebView

Xamarin Forms - GIF stored put into WebView

我在问自己这件事,但在网上找不到有趣的东西。我从未与 WebView 合作过,但我发现了一些关于它的东西并且我似乎可以创建自己的 WebPage.

那么是否可以创建一个WebPage(在WebView中)并放入这个WebView(或WebPage)一个GIF ?

我也明白,我想,我可以 link WebViewGIF 的 link 在网络上,但是对于数据交换,我想把它存储在 phone 而不是每次都加载它。

那么,有可能吗?

提前致谢!

来自 Xamarins docs:

// define a interface
public interface IBaseUrl { string Get(); }

// load html
var html = new HtmlWebViewSource ();
html.BaseUrl = DependencyService.Get<IBaseUrl> ().Get ();

htmlSource.Html = @"<html>
    <head>
    <link rel=""stylesheet"" href=""default.css"">
    </head>
    <body>
    <h1>Xamarin.Forms</h1>
    <p>The CSS and image are loaded from local files!</p>
    <img src='Images/XamarinLogo.png'/>
    </body>
    </html>";

webView.Source = html;

然后您需要为您希望支持的每个平台实施 IBaseUrl。对于 iOS,它看起来像这样:

[assembly: ExportRenderer (typeof (BaseUrlWebView), typeof (BaseUrlWebViewRenderer))]
namespace WorkingWithWebview.iOS {
    public class BaseUrlWebViewRenderer : WebViewRenderer  {
        public override void LoadHtmlString (string s, NSUrl baseUrl)  {
            baseUrl = new NSUrl (NSBundle.MainBundle.BundlePath, true);
            base.LoadHtmlString (s, baseUrl);
        }
    }
}