microsoft-ui-xaml icon indicating copy to clipboard operation
microsoft-ui-xaml copied to clipboard

Using Mica\Acrylic backdrop with TintColor has problem with Dark theme

Open ghost1372 opened this issue 1 year ago • 0 comments

Describe the bug

i am using Mica or Acrylic Backdrop with a TintColor, this is my Mica Backdrop class

public sealed class MicaSystemBackdrop : SystemBackdrop
{
    public readonly MicaKind Kind;
    private MicaController micaController;

    public SystemBackdropConfiguration BackdropConfiguration { get; private set; }

    private Color tintColor;
    public Color TintColor
    {
        get { return tintColor; }
        set
        {
            tintColor = value;
            if (micaController != null)
            {
                micaController.TintColor = value;
            }
        }
    }

    public MicaSystemBackdrop(MicaKind micaKind)
    {
        Kind = micaKind;
    }
    protected override void OnTargetConnected(ICompositionSupportsSystemBackdrop connectedTarget, XamlRoot xamlRoot)
    {
        base.OnTargetConnected(connectedTarget, xamlRoot);

        micaController = new MicaController() { Kind = this.Kind };
        micaController.AddSystemBackdropTarget(connectedTarget);
        BackdropConfiguration = GetDefaultSystemBackdropConfiguration(connectedTarget, xamlRoot);
        micaController.SetSystemBackdropConfiguration(BackdropConfiguration);
    }

    protected override void OnTargetDisconnected(ICompositionSupportsSystemBackdrop disconnectedTarget)
    {
        base.OnTargetDisconnected(disconnectedTarget);

        if (micaController is not null)
        {
            micaController.RemoveSystemBackdropTarget(disconnectedTarget);
            micaController = null;
        }
    }
}

When my app runs, i set Default TintColor like this:

TintColor = new MicaController().TintColor;

if my app start with a Dark Theme, i get this: image

if, i disable TintColor (commenting TintColor code) and i start app again, you can see that dark theme is load correctly (without tintColor): image

Steps to reproduce the bug

I tried the following code, But it had no effect

protected override void OnDefaultSystemBackdropConfigurationChanged(ICompositionSupportsSystemBackdrop target, XamlRoot xamlRoot)
    {
        if (target != null)
        {
            var config = GetDefaultSystemBackdropConfiguration(target, xamlRoot);
            micaController.SetSystemBackdropConfiguration(config);
        }
    }

Expected behavior

TintColor should be loaded correctly with Light/Dark Theme

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.4.4: 1.4.231219000

Windows version

Windows 11 (22H2): Build 22621

Additional context

this is my sample app, run app, change application theme to Dark, and run app again. App18.zip

ghost1372 avatar Jan 26 '24 09:01 ghost1372