如何将白色添加到 Web 视图背景

How to add White color to web view Background

我有一个 Web 视图来显示 pdf。当它显示 pdf 时它没有占据整个区域这不是我的问题,但它的背景颜色显示一种深色背景我需要将深色去除为白色如何在 xamarin 表单中执行此操作

您是否使用 Google 文档查看器加载远程 pdf 文件?如果是这样,则无法删除额外的边框,因为它由 Google 控制。我没有找到任何 api 来改变外观。但是你可以改变嵌入的样式:

protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
{
    base.OnElementChanged(e);

    if (e.NewElement != null)
    {
        var customWebView = Element as CustomWebView;
        Control.Settings.AllowUniversalAccessFromFileURLs = true;
        Control.LoadUrl("https://drive.google.com/viewerng/viewer?embedded=true&url=" + customWebView.Uri);
    }
}

当我们将 embedded 设置为 true 时,它​​会显示浅灰色边框。

您必须在表单上创建自定义控件以使用上面的自定义渲染器:

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); }
    }
}

最后在XAML中使用:

<StackLayout>
    <local:CustomWebView VerticalOptions="FillAndExpand" Uri="http://www.africau.edu/images/default/sample.pdf" />
</StackLayout>

更新:

如果pdf有几页,它可以滚动: