question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Working with Mica

See original GitHub issue

I know Mica is not supported yet. However, with the help of some PInvoke functions, Mica is activated on WPF apps image

so I tried to do the same in WinUI3 preview 3

[DllImport("dwmapi.dll")]
        public static extern int DwmSetWindowAttribute(IntPtr hwnd, DwmWindowAttribute dwAttribute, ref int pvAttribute, int cbAttribute);

        [Flags]
        public enum DwmWindowAttribute : uint
        {
            DWMWA_USE_IMMERSIVE_DARK_MODE = 20,
            DWMWA_MICA_EFFECT = 1029
        }
        public static void EnableMica(IntPtr source, bool darkThemeEnabled)
        {
            int trueValue = 0x01;
            int falseValue = 0x00;

            // Set dark mode before applying the material, otherwise you'll get an ugly flash when displaying the window.
            if (darkThemeEnabled)
                DwmSetWindowAttribute(source, DwmWindowAttribute.DWMWA_USE_IMMERSIVE_DARK_MODE, ref trueValue, Marshal.SizeOf(typeof(int)));
            else
                DwmSetWindowAttribute(source, DwmWindowAttribute.DWMWA_USE_IMMERSIVE_DARK_MODE, ref falseValue, Marshal.SizeOf(typeof(int)));

            DwmSetWindowAttribute(source, DwmWindowAttribute.DWMWA_MICA_EFFECT, ref trueValue, Marshal.SizeOf(typeof(int)));
        }

public MainWindow()
        {
            this.InitializeComponent();
            IntPtr hwnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
            EnableMica(hwnd, true);
        }

TitleBar activates Mica well, but not Windows content

image

Is there a solution?😁

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
IcySnexcommented, Apr 20, 2022

You need to set the background of your application to transparent.

You can do this via Win32 API calls. I have created a sample project here: https://github.com/IcySnex/WinUI3-Transparent-Mica-Acrylic-Blurred. You can also look at a video here: https://www.youtube.com/watch?v=mfS8PT9Z3u8. But be aware that you need to have at least the WindowsAppSDK version 1.1 - preview 1.

0reactions
dongle-the-gadgetcommented, Apr 21, 2022

That method depends on a private API that has been removed since 22494+ (in 22523 and later it’s replaced. The proper way is to use Windows.UI.Composition.Compositor, however this approach requires either a swapchain or a HwndHost (or some other way idk), the latter causes the airspace problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mica Quickstart Guide: 61 Uses for Mica Powder
The guide features 61 of the best projects and uses for mica powder ... Safety First - Wear a mask and gloves when...
Read more >
How to use Mica Powder - The Bench
Create moonstone effects by taking small amounts of the powder and mixing it into epoxy resin. This design works particularly well with a...
Read more >
What Is Mica Powder and 23 Ways to Use It
Mica powder works best when used with melt-and-pour soap bases, in my personal experience. You simply pour some of the powder into the...
Read more >
The Ultimate Guide on How to Use Mica Powder
If you're working with paper, it's as simple as adding the powder to water and brushing or spraying it on! You can mix...
Read more >
7 Ways To Use Mica Powder in Craft Projects
Mica powder is an excellent colorant for various projects, including polymer clay. The stickiness of the clay means you can work the mica...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found