如何在创作者更新中将后备颜色应用于亚克力

How to apply fallback color to acrylic in creators update

关注此 post 之后:

我已在创意者更新中成功将 Acrylic 添加到我的应用程序中。不幸的是,当在 Windows 的颜色设置中禁用透明度时,我的应用程序的背景要么在浅色主题中是非常深的灰色,要么在深色主题中几乎完全是黑色,尽管我设置了我的网格背景在使 window 透明的相关面板上方: Background="{ThemeResource CommandBarBackground}".

有谁知道如何在 creators update 中实现回退颜色,以便在禁用透明度时,背景切换到设置的原始背景颜色。

Does anyone know how to implement the fallback color in the creators update so that when transparency is disabled, the background switches to the original background color that was set.

有一个AdvancedEffectsEnabled property in U​ISettings Class表示系统透明效果设置是否启用。当它returns false时,您可以将背景重置为原始背景颜色。

并且当启用或禁用系统高级UI效果设置时,也会发生AdvancedEffectsEnabledChanged事件。您可以将此事件与 AdvancedEffectsEnabled 属性 结合使用,如下所示:

UISettings uiSettings = new UISettings();
uiSettings.AdvancedEffectsEnabledChanged += UiSettings_AdvancedEffectsEnabledChangedAsync;

private async void UiSettings_AdvancedEffectsEnabledChangedAsync(UISettings sender, object args)
{
    if (sender.AdvancedEffectsEnabled)
    {
        await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
        {
            //TODO: Apply Acrylic Accent
        });
    }
    else
    {
        await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
        {
            //TODO: Reset Background
        });
    }
}

请注意,AdvancedEffectsEnabledChanged 事件可能不会在 UI 线程中引发。要更改背景颜色,我们需要 Core Dispatcher.RunAsync 方法。