WP7 WebBrowser 的透明背景(解决方法)
WP7的WebBrowser无法设置透明背景。为了给人留下透明背景的印象,我想做以下解决方法。我想要:
- 找到WebBrowser在页面上的位置和大小。
- 获取页面的背景图片。
- 使用我在步骤 1 中找到的值对其进行裁剪。
- 将结果保存在isolatedStorage中
- 解析 HTML 并放置
MyWebBrowser.NavigateToString(NewHtmlString);
我认为这应该是透明背景的解决方法并且应该有效。
现在我尝试在第 5 步中放置任何 .jpg 图像(假设为 test.jpg
)。 但失败了。我将文件的“构建操作”属性设置为“内容”。它被放置在项目的根目录中。并且 不起作用。网络浏览器的背面仍然是白色的。
我做错了什么?
更新: 第5步解决了。
2克劳斯:不!不仅来自网络。我将html文件和图像文件保存到IsolatedStorage中,并且WebBrowser可以将图像显示为背景。
现在的问题是背景无法修复。我尝试了很多不同风格的东西。我还尝试在文本后面添加一个固定的 div。什么都不起作用。图片总是与文字一起滚动。我尝试添加 onscroll 事件并传递滚动值以将 div 向相反方向移动,但 div 粘在页面上:(
有什么想法吗?
It's not possible to set transparent background for WebBrowser of WP7. To make impression of transparent background I want to do the following workaround. I want:
- To find a position and size of WebBrowser on the page.
- To get page's background image.
- Crop it with values what I found on step 1.
- To save result in IsolatedStorage
- To parse HTML and place
<body background="RESULTBACKGROUND">
MyWebBrowser.NavigateToString(NewHtmlString);
I think this should be a workaround of transparent background and should work.
For now I am trying just to place any .jpg image (let's say test.jpg
) on step 5.
But fail. I have "Build Action" property of file set to "Content". It is placed in the root of the project. And <body background="test.jpg">
not working. Back of the WebBrowser is still white.
What I am doing wrong?
UPD:
Step 5 is solved.
2Claus: No! Not only from web. I saved both html file and image file to IsolatedStorage and WebBrowser can show image as a backgroud.
Now the problem is that background cannot be fixed. I tried many differrent things with styles. I also tried to add a fixed div behind my text. Nothing works. The picture is always scrolling with a text. I tried to add onscroll event and pass it scrolled value to move the div in an opposite direction, but div is glued to the page :(
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
因此,假设您正在谈论 WebBrowser 控件,您会忘记 HTML 只能引用万维网上的 url。
因此,您要么需要在网站上托管背景图像,要么需要注入 CSS 样式,将背景设置为白色或黑色(平台的两种默认背景颜色)。
So assuming you're talking about the WebBrowser control, you're forgetting that the HTML only can refer to urls on the world wide web.
So either you need to host your background images on a website, or you need to inject a CSS style that sets the background to either white or black (the two default background-colours of the platform).
对于 WebBrowser,您实际上不必将其保存到 ISO 即可在页面上进行更改。您可以正常加载它并导航到它,然后使用 InvokeScript 通过自定义 JS 代码进行更改。但这可能有点棘手,因为您可能需要严重依赖评估和字符串化。克劳斯提到的问题仍然存在——但你需要做一些实验。在 Mango 版本和 SDK 7.1+ 中,平台支持 is://path/file 形式的 IsoltatedStorage 图像源 - 也许 - 也许 - 也许平方 - 网络浏览器的渲染器也支持它们 - 然后将你的 bkg 的 url 设置为这样就可以了。但我对此表示怀疑,因为这可能被视为一些轻微的安全漏洞等
For WebBrowser, You don't actually have to save it to the ISO to make changes on the page. You can load it navigate to it normally, and then use InvokeScript to make the changes via custom JS code. It can be a little tricky though, as you will probably need to heavily rely on the eval and stringization. The problem mentioned by Claus is still there - but you need to do some experiments. With the Mango release and SDK 7.1+, the platform support IsoltatedStorage imagesources in the form of is://path/file - maybe - maybe - maybe squared - the webbrowser's renderer udnerstands them too - then setting your bkg's url to such would work. I doubt though, as it could be seen as some minor security breach, etc
我现在遇到了同样的背景固定图像问题。对于在这里徘徊的人,我解决了将内容放入固定高度容器(div)中的问题,因此容器内容正在滚动,而不是html页面,从而使背景图片“固定”。
当然,背景位置和 div 高度是专门针对页面中的 Web 浏览器位置及其大小而设置的。
I now bumped into the same background fixed image problem. For someone wandering here I solved it placing content into a fixed-height container (div) therefore the container contents is being scrolled and not the html page, leaving background picture "fixed".
Of course background-position and div height is set specifically for a WebBrowser position in page and it's size.