CefSharp WebBrowser Example in WPF (transparency)

。_饼干妹妹 提交于 2019-12-23 04:22:26

问题


I'm working with WPF and c# (using Visual Studio 2013) and I want to develop an application with a transparent background and a webbrowser. I understand that this is an issue of the default webbrowser... but I want to find another solution. I found other webbrowser components like CefSharp that is based on chromium. I'd like to know if is possible using a transparent background using the CefSharp browser and I'd like that someone explain me step by step how to implement a very simple webbrowser (I found some article but I was not able to implement a working application). If you think that there are other better components please suggest me and explain me how to make them working. Thank you for your attention and for the replies.


回答1:


This is just a quick proof of concept hack based on CefSharp.Wpf.Example to see if it was doable. Depending on what you want I think it is possible to make (some) web pages transparent.

On the picture below you see CefSharp.Wpf.Example on top of Visual Studio. There's also a partial DevTools window from CefSharp in front in the lower left corner.

Here is what I did (refer to the picture below):

  1. Add WindowState="Normal" Opacity=".75" AllowsTransparency="True" WindowStyle="None" MinHeight="400" MinWidth="600" to the <Window> element of MainWindow.Xaml
  2. Add a call somewhere when the browser is initialized to its ShowDevTools() method.
  3. I then used DevTools to set the <body>s background alpha to zero on the page loaded.

Depending on what you need you will have to experiment with WPF Opacity values yourself. Also depending on the web page you need to display removing the actual background color on different elements may need some tweaking. As you can see from the example above it just needed setting one value to remove the white background on the Google search page. You can use the ExecuteJavascriptAsync() method mentioned in the CefSharp FAQ wiki page to inject JavaScript in pages you navigate to.



来源:https://stackoverflow.com/questions/26928008/cefsharp-webbrowser-example-in-wpf-transparency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!