问题
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):
- Add
WindowState="Normal" Opacity=".75" AllowsTransparency="True" WindowStyle="None" MinHeight="400" MinWidth="600"
to the<Window>
element ofMainWindow.Xaml
- Add a call somewhere when the browser is initialized to its
ShowDevTools()
method. - 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