简体   繁体   English

如何在 WPF 中设置 WebView2 控件的不透明度

[英]How can I set Opacity of WebView2 control in WPF

How can I set Opacity of WebView2 control in WPF I need to change opacity of WebView2 from 0 to 1 by using Storyboard but when I am trying to set "Opacity =0" to WebView2 it doesn't get apply.如何在 WPF 中设置 WebView2 控件的不透明度我需要使用 Storyboard 将 WebView2 的不透明度从 0 更改为 1,但是当我尝试将“Opacity = 0”设置为 WebView2 时,它不适用。 So is there any way I can dynamically set its opacity?那么有什么办法可以动态设置它的不透明度吗?

WebView2 is not a native wpf control,it does not support transparency settings. WebView2不是原生的wpf控件,不支持透明度设置。

you can use CEFSharp ,it provides the same feature of WebView2, and supports transparency settings.你可以使用CEFSharp ,它提供与 WebView2 相同的功能,并支持透明度设置。

NuGet\Install-Package CefSharp.Wpf -Version 108.4.130

It's simply impossible.这简直是不可能的。 WebView2 is HwndHost . WebView2 是HwndHost it means they are native win32 windows placed exactly in location of specified in your WPF. So It's not a WPF element you can manipulate.这意味着它们是本机 win32 windows 正好放置在您的 WPF 中指定的位置。因此它不是您可以操作的 WPF 元素。

If you want to somehow hide the WebView for a while, you can use Visibility.如果您想暂时隐藏 WebView,可以使用可见性。

<wv2:WebView2 Visibility="Hidden" MinHeight="300" />

Above that control you can show a loading icon or something and animate it, not the WebView itself.在该控件上方,您可以显示加载图标或其他内容并为其设置动画,而不是 WebView 本身。

<Grid>
    <wv2:WebView2 Visibility="Hidden" Width="500" Height="500" />
    <custom:MyFancyLoadingControl Visibility="Visible" Width="500" Height="500" />
</Grid>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM