You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

WinUI 3(Reunion)主窗口透明设置、Win10窗口圆角实现及Mica材质兼容性咨询

Answers to Your WinUI 3 Questions

Hey there! No worries at all—everyone starts somewhere with WinUI, so don’t stress about being a beginner. Let’s break down your questions one by one:

1. Transparent Main Window for Shaped Windows in WinUI 3 (Windows App SDK)

Absolutely, you can achieve a transparent window for shaped UIs in WinUI 3, though the approach is a bit different from WPF. Here’s how:

  • First, disable the window border and title bar: You’ll need to use the AppWindow API to modify the window presenter. In your code-behind (e.g., MainWindow.xaml.cs), add this logic (usually in the constructor):
    using Microsoft.UI.Windowing;
    using Microsoft.UI.Xaml;
    
    public MainWindow()
    {
        this.InitializeComponent();
        var appWindow = GetAppWindowForCurrentWindow();
        if (appWindow != null)
        {
            var overlappedPresenter = appWindow.Presenter as OverlappedPresenter;
            if (overlappedPresenter != null)
            {
                // Disable border and title bar
                overlappedPresenter.IsBorderEnabled = false;
                overlappedPresenter.SetBorderAndTitleBar(false, false);
            }
        }
    }
    
    // Helper method to get the AppWindow for the current XAML Window
    private AppWindow GetAppWindowForCurrentWindow()
    {
        var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
        var windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hWnd);
        return AppWindow.GetFromWindowId(windowId);
    }
    
  • Set the window background to transparent: In your MainWindow.xaml, set the Window element’s Background to Transparent:
    <Window
        x:Class="YourAppNamespace.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Background="Transparent">
        <!-- Your UI content here -->
    </Window>
    
  • Create shaped UI: To make an irregular window, use the Clip property on your root container (like a Grid or Border) to define the shape you want. For example, a circular window could use an EllipseGeometry as the clip.

2. Windows 11-Style Window Rounded Corners on Windows 10

Windows 11’s rounded window corners are a system-level feature that Windows 10 doesn’t natively support. However, you can simulate this effect in WinUI 3 on Windows 10:

  • Hide the default window border: Use the same AppWindow logic from the first question to disable the border.
  • Add a rounded container: Wrap your entire UI in a Border with a CornerRadius set to match Windows 11’s typical 16px radius, and set a solid background. Your XAML would look something like this:
    <Window Background="Transparent">
        <Grid>
            <Border CornerRadius="16" Background="White" Padding="10">
                <!-- Your main UI content goes here -->
            </Border>
        </Grid>
    </Window>
    

This creates the illusion of a rounded window since the transparent outer window hides behind the rounded border. Note this is a custom implementation, not the native system-rounded corners from Windows 11.

3. Mica Material Support on Windows 10

Unfortunately, Mica is exclusive to Windows 11 and later versions. The Mica brush APIs are part of the Windows 11 SDK and won’t work on Windows 10.

If you want a similar blurred background effect on Windows 10, you can use the AcrylicBrush (available on Windows 10 1809 and above). Acrylic provides a semi-transparent, blurred background, though it’s not the same as Mica’s more subtle, static appearance.


内容的提问来源于stack exchange,提问作者AlexPalex

火山引擎 最新活动