WP7 WebBrowser 的透明背景(解决方法)

发布于 2024-12-05 09:47:55 字数 739 浏览 0 评论 0原文

WP7的WebBrowser无法设置透明背景。为了给人留下透明背景的印象,我想做以下解决方法。我想要:

  1. 找到WebBrowser在页面上的位置和大小。
  2. 获取页面的背景图片。
  3. 使用我在步骤 1 中找到的值对其进行裁剪。
  4. 将结果保存在isolatedStorage中
  5. 解析 HTML 并放置
  6. 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:

  1. To find a position and size of WebBrowser on the page.
  2. To get page's background image.
  3. Crop it with values what I found on step 1.
  4. To save result in IsolatedStorage
  5. To parse HTML and place <body background="RESULTBACKGROUND">
  6. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

迷爱 2024-12-12 09:47:55

因此,假设您正在谈论 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).

多孤肩上扛 2024-12-12 09:47:55

对于 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

平生欢 2024-12-12 09:47:55

我现在遇到了同样的背景固定图像问题。对于在这里徘徊的人,我解决了将内容放入固定高度容器(div)中的问题,因此容器内容正在滚动,而不是html页面,从而使背景图片“固定”。

body 
{ 
    background-image:url('...'); 
    background-position:-20px -150px; 
    background-repeat:no-repeat; 
    background-attachment:fixed; 
}
div
{
    height:300px;
    overflow:scroll;
}

当然,背景位置和 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".

body 
{ 
    background-image:url('...'); 
    background-position:-20px -150px; 
    background-repeat:no-repeat; 
    background-attachment:fixed; 
}
div
{
    height:300px;
    overflow:scroll;
}

Of course background-position and div height is set specifically for a WebBrowser position in page and it's size.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文