CSS Id选择器阻止所有内容在Xamarin中显示.Android 10的Forms WebView



我有一个WebView,我分配一个HTML片段使用HtmlWebViewSource分配给Source

自从瞄准Android 10以来,WebView已经停止显示所有内容。

我已经缩小了一个字符,使内容显示和不显示内容之间的差异。HTML包含一个<style>部分。

hello {}

…然后显示内容。

#hello {}

…然后没有内容显示。(hello不指向任何东西)

显然,#字符表示一个Id选择器。

那么,为什么针对Android 10突然使我的HTML停止显示基于这样一个简单的改变CSS?

我进一步缩小了范围。在<head>标签中…

<style>#</style>->没有HTML显示

<style></style>->HTML显示。

<style>.</style>->HTML显示。

我还在服用Xamarin。4 .

形式

下面的代码为我工作。请核对一下。

<!DOCTYPE html>
<html>
<head>
<style>
/* Style the element with the id "hello" */
#hello {
background-color: lightblue;
color: black;
padding: 30px;
text-align: center;
}
/* Style all elements with the class name "Line" */
.Line {
background-color: #9815B0;
color: white;
padding: 10px;
}
</style>
</head>
<body>
<!-- An element with a unique id -->
<h1 id="hello">Page1</h1>
<!-- Multiple elements with same class -->
<h2 class="Line">Line1</h2>
<p>number 1.</p>
<h2 class="Line">Line2</h2>
<p>number 2.</p>
<h2 class="Line">Line3</h2>
<p>number 3.</p>
</body>
</html>

我修复了这个问题。我使用一个类从WebView派生自定义渲染器,这是从继承…

ViewRenderer<MyWebView, Android.Webkit.WebView>

我不知道我为什么这样做。它至少允许从相关类(处理Javascript)引用渲染器上的方法,而不必将渲染器上的Element强制转换为从WebView派生的自定义类。

因此,我使自定义渲染器继承自标准WebViewRenderer,并删除了创建本机控件并加载其HTML片段的代码,现在可以自动处理。本地WebView的自定义与以前一样。

我不知道为什么我不能再创建自己的本地WebView而不得到这个奇怪的错误。