Create a transparent windows on WinUI 3 latest
- User
Create a transparent windows on WinUI 3 latest
Assistant
Here's how to create a transparent window in WinUI 3:
// In App.xaml.cs public partial class App : Application { protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args) { m_window = new MainWindow(); // Get the window handle (HWND) var windowNative = m_window as IWindowNative; var hwnd = windowNative.WindowHandle; // Enable the default system backdrop (Mica/Acrylic) var backdrop = new Microsoft.UI.Composition.SystemBackdrops.MicaController(); Microsoft.UI.WindowId windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hwnd); Microsoft.UI.Windowing.AppWindow appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId); // Set window properties if (appWindow is not null) { // Make window transparent appWindow.TitleBar.ExtendsContentIntoTitleBar = true; var presenter = appWindow.Presenter as OverlappedPresenter; presenter.SetBorderAndTitleBar(false, false); presenter.IsMaximizable = false; presenter.IsMinimizable = false; // Optional: Set a custom transparency level m_window.SystemBackdrop = new MicaBackdrop() { Kind = MicaKind.Base }; } m_window.Activate(); } private Window m_window; } // MainWindow.xaml <Window x:Class="TransparentWindowApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Background="Transparent"> <Grid> <!-- Your content here --> </Grid> </Window> // IWindowNative interface for getting the window handle internal interface IWindowNative { IntPtr WindowHandle { get; } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.