问题描述
我正在尝试使我的 Windows 7 Phone 应用程序上的 WebBrowser 控件透明,因此它可以与应用程序的其余部分具有相同的主题,但我尝试过的任何内容都没有成功.我仍然需要能够看到 HTML 文本,但只需让背景透明即可.在控件中使用 CSS 似乎不起作用,我也无法通过 XAML 使其工作.这可能吗?这个帖子并不令人鼓舞.
I am trying to make a WebBrowser control on my Windows 7 Phone app transparent, so it can have the same theme as the rest of the app, but I have had no success with anything I have tried.I need to still be able to see the HTML text, but just have the background be transparent. Using CSS in the control doesn't seem to work, and I can't get it to work via XAML either. Is this possible? This post, was not encouraging.
推荐答案
这不可能.浏览器引擎始终为 HTML 页面呈现背景颜色.您可以为 BODY 标签指定一种颜色,但透明"的值将始终以白色结束.您分配给 WebBrowser XAML 元素的背景色实际上没有任何影响,因为浏览器引擎本质上是在其顶部呈现的.
This isn't possible. The browser engine always renders a background color for the HTML page. You can assign a color to the BODY tag but a value of 'transparent' will always end up white. The Background color you assign to the WebBrowser XAML element really has no effect as the browser engine essentially renders over the top of it.
与您的应用主题相匹配的最佳选择是通过 InvokeScript 将应用主题背景颜色传递到 HTML 页面中,然后将其设置在 BODY 元素上的 Javascript 函数.这假设您可以控制正在加载的 HTML 内容.(另外,不要忘记通过 IsScriptEnabled 启用脚本.)
Your best bet to match your app theme is to pass the app theme background color into the HTML page via InvokeScript to a Javascript function that will then set it on the BODY element. This assumes that you have control of the HTML content you are loading. (Also, don't forget to enable script via IsScriptEnabled.)
这篇关于使 Web 浏览器透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!