Fix WebView2 interaction on transparent window with opaque rectangle

This commit is contained in:
Stone_Red
2025-12-25 19:57:39 +01:00
parent 0bb5b10dba
commit 3edb2cff84
2 changed files with 4 additions and 3 deletions
@@ -21,8 +21,9 @@
<Border x:Name="border" Background="Transparent" CornerRadius="10"> <Border x:Name="border" Background="Transparent" CornerRadius="10">
<Grid> <Grid>
<wv2:WebView2 x:Name="webView" DefaultBackgroundColor="Transparent" CoreWebView2InitializationCompleted="webView_CoreWebView2InitializationCompleted" /> <wv2:WebView2 x:Name="webView" DefaultBackgroundColor="Transparent" CoreWebView2InitializationCompleted="WebView_CoreWebView2InitializationCompleted" />
<Rectangle Fill="Transparent" IsHitTestVisible="True" /> <!-- WORKAROUND: This rectangle exists to allow interaction with the WebView2 when the window is transparent -->
<Rectangle Fill="#01000000" />
</Grid> </Grid>
</Border> </Border>
</Grid> </Grid>
@@ -230,7 +230,7 @@ public partial class WebPluginWindow : Window, IPluginWindow
tileBar.CaptionHeight = ActualHeight - 10; tileBar.CaptionHeight = ActualHeight - 10;
} }
private void webView_CoreWebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e) private void WebView_CoreWebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e)
{ {
webView.CoreWebView2.DOMContentLoaded += (_, _) => ThemeChanged(); webView.CoreWebView2.DOMContentLoaded += (_, _) => ThemeChanged();
} }