Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 17, 2025

SVG previews were always dark regardless of system theme because WebView2-based panels lacked the theme toggle button present in regular image previews.

Changes

  • Created SvgImagePanel.xaml: Added WPF button overlay on WebView2 using same CaptionButtonStyle as ImagePanel
  • Refactored SvgImagePanel.cs: Converted from inheriting WebpagePanel to standalone UserControl with XAML support
    • Added ContextObject property for theme access
    • Added OnBackgroundColourOnClick() handler to toggle Dark/Light themes
    • Added UpdateWebViewBackgroundColor() to dynamically update WebView2 background color
    • Theme preference persists via SettingHelper.Set("LastTheme", ...)
  • Extended to inherited panels: LottieImagePanel, TgsImagePanel, SvgaImagePanel now call UpdateWebViewBackgroundColor() in Preview()
  • Updated WebHandler: Passes ContextObject to all WebView2-based panels for theme synchronization

Implementation

// SvgImagePanel.cs - Theme toggle handler
private void OnBackgroundColourOnClick(object sender, RoutedEventArgs e)
{
    var newTheme = ContextObject.Theme == Themes.Dark ? Themes.Light : Themes.Dark;
    ContextObject.Theme = newTheme;
    SettingHelper.Set("LastTheme", (int)newTheme, "QuickLook.Plugin.ImageViewer");
    UpdateWebViewBackgroundColor();
}

protected void UpdateWebViewBackgroundColor()
{
    var isDark = ContextObject?.Theme == Themes.Dark;
    _webView.DefaultBackgroundColor = isDark 
        ? Color.FromArgb(255, 32, 32, 32) 
        : Color.White;
}

All WebView2-based image formats (SVG, Lottie, TGS, SVGA) now support theme toggling with consistent behavior across the image viewer plugin.

Original prompt

This section details on the original issue you should resolve

<issue_title>SVG preview window is always dark</issue_title>
<issue_description>Describe the bug
SVG preview window is always dark, when other file types are all light.

To Reproduce
Steps to reproduce the behavior:

  1. Set the system to light mode
  2. Preview a SVG file
  3. See that the preview window opens in dark mode

Expected behavior
The preview window opens in light mode to match the system.

Desktop (please complete the following information):

  • OS Version: Windows 11 25H2 build 26200.7019
  • QuickLook Version: v4.2.2 from Microsoft Store

Screenshots and Exception Log
Side note that it has a darker title bar than other file types even also on dark mode:
SVG file preview window title bar in dark mode
MSIX file preview window title bar in dark mode</issue_description>

<agent_instructions>这是因为图片预览插件中,SVG控件没有切换浅色/深色模式的按钮,如果用户在PNG预览时切换了深色模式,就会导致SVG渲染一直是深色模式,帮我在SVG等webview2控件时也有个切换按钮,要求不要用web实现,用WPF控件覆盖在webview2上方的按钮(与PNG预览的一致)</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix SVG preview window to match system light mode Add theme toggle button to SVG and WebView2-based image previews Nov 17, 2025
Copilot AI requested a review from emako November 17, 2025 09:28
Copy link
Member

@emako emako left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even so, after the webview2 control is inserted, the button will be blocked. Is it true that Webview2 cannot be laid out together with WPF?


// Add WebView2 to the Grid at the first position (behind the button)
var grid = (Grid)Content;
grid.Children.Insert(0, _webView);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even so, after the webview2 control is inserted, the button will be blocked. Is it true that Webview2 cannot be laid out together with WPF?

@emako emako marked this pull request as ready for review November 19, 2025 16:13
@emako emako marked this pull request as draft November 19, 2025 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SVG preview window is always dark

2 participants