Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/DesktopFlyouts.Shared/DesktopFlyout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,27 @@ public void Hide()
}

#if WASDK
internal SystemBackdrop? CreateIslandSystemBackdrop()
internal SystemBackdrop? CreateIslandSystemBackdrop(ElementTheme islandTheme)
{
if (!IsBackdropEnabled)
return null;

var useLightTheme = IsLightTheme(islandTheme);

return BackdropKind switch
{
DesktopFlyoutBackdropKind.Mica => new DesktopFlyoutMicaBackdrop(),
_ => new DesktopFlyoutAcrylicBackdrop(),
DesktopFlyoutBackdropKind.Mica => new DesktopFlyoutMicaBackdrop(useLightTheme),
_ => new DesktopFlyoutAcrylicBackdrop(useLightTheme),
};
}

private static bool IsLightTheme(ElementTheme theme)
{
return theme switch
{
ElementTheme.Light => true,
ElementTheme.Dark => false,
_ => GeneralHelpers.IsTaskbarLight(),
};
}
#endif
Expand Down Expand Up @@ -814,6 +826,8 @@ private void UpdateFlyoutTheme()
foreach (var island in Islands)
island.RequestedTheme = ElementTheme.Dark;
}

UpdateIslandBackdrops();
}

private void UpdateIslandBackdrops()
Expand Down
2 changes: 1 addition & 1 deletion src/DesktopFlyouts.Shared/DesktopFlyoutIsland.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private static double GetBackdropCornerRadius(double cornerRadius)
internal void UpdateOwnerBackdrop()
{
TemplateSettings.SystemBackdrop = Owner is DesktopFlyout owner
? owner.CreateIslandSystemBackdrop()
? owner.CreateIslandSystemBackdrop(RequestedTheme)
: null;
}

Expand Down
17 changes: 4 additions & 13 deletions src/DesktopFlyouts.Shared/Helpers/BackdropControllerHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ internal static class BackdropControllerHelpers
{
private static UISettings UISettings => field ??= new UISettings();

internal static DesktopAcrylicController? GetAcrylicController(SystemBackdropTheme theme)
internal static DesktopAcrylicController? GetAcrylicController(bool useLightTheme)
{
if (!DesktopAcrylicController.IsSupported())
return null;

if (GeneralHelpers.IsTaskbarColorPrevalenceEnabled())
return GetAccentedAcrylicController();

return IsLightTheme(theme)
return useLightTheme
? GetLightAcrylicController()
: GetDarkAcrylicController();
}

internal static MicaController? GetMicaController(SystemBackdropTheme theme)
internal static MicaController? GetMicaController(bool useLightTheme)
{
if (!MicaController.IsSupported())
return null;

if (GeneralHelpers.IsTaskbarColorPrevalenceEnabled())
return GetAccentedMicaController();

return IsLightTheme(theme)
return useLightTheme
? GetLightMicaController()
: GetDarkMicaController();
}
Expand Down Expand Up @@ -109,15 +109,6 @@ internal static class BackdropControllerHelpers
};
}

private static bool IsLightTheme(SystemBackdropTheme theme)
{
return theme switch
{
SystemBackdropTheme.Light => true,
SystemBackdropTheme.Dark => false,
_ => GeneralHelpers.IsTaskbarLight(),
};
}
}
#endif
}
21 changes: 8 additions & 13 deletions src/DesktopFlyouts.Shared/Helpers/DesktopFlyoutSystemBackdrops.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,45 +55,40 @@ protected override void OnDefaultSystemBackdropConfigurationChanged(IComposition
if (!_targets.TryGetValue(target, out var state))
return;

ApplyConfiguration(state.Configuration, target, xamlRoot);
ApplyConfiguration(state.Configuration);
state.Controller.SetSystemBackdropConfiguration(state.Configuration);
}

private SystemBackdropConfiguration CreateConfiguration(ICompositionSupportsSystemBackdrop target, XamlRoot xamlRoot)
{
var configuration = new SystemBackdropConfiguration();
ApplyConfiguration(configuration, target, xamlRoot);
ApplyConfiguration(configuration);

return configuration;
}

private void ApplyConfiguration(SystemBackdropConfiguration configuration, ICompositionSupportsSystemBackdrop target, XamlRoot xamlRoot)
private static void ApplyConfiguration(SystemBackdropConfiguration configuration)
{
var defaultConfiguration = GetDefaultSystemBackdropConfiguration(target, xamlRoot);

configuration.Theme = defaultConfiguration.Theme;
configuration.IsInputActive = true;
}

private sealed record TargetState(ISystemBackdropControllerWithTargets Controller, SystemBackdropConfiguration Configuration);
}

internal sealed partial class DesktopFlyoutAcrylicBackdrop : DesktopFlyoutSystemBackdrop
internal sealed partial class DesktopFlyoutAcrylicBackdrop(bool useLightTheme) : DesktopFlyoutSystemBackdrop
{
protected override ISystemBackdropControllerWithTargets? TryCreateController(SystemBackdropConfiguration configuration)
{
return BackdropControllerHelpers.GetAcrylicController(configuration.Theme);
return BackdropControllerHelpers.GetAcrylicController(useLightTheme);
}
}

internal sealed partial class DesktopFlyoutMicaBackdrop : DesktopFlyoutSystemBackdrop
internal sealed partial class DesktopFlyoutMicaBackdrop(bool useLightTheme) : DesktopFlyoutSystemBackdrop
{
protected override ISystemBackdropControllerWithTargets? TryCreateController(SystemBackdropConfiguration configuration)
{
var controller = BackdropControllerHelpers.GetMicaController(configuration.Theme);
if (controller is not null)
controller.Kind = MicaKind.Base;

var controller = BackdropControllerHelpers.GetMicaController(useLightTheme);
controller?.Kind = MicaKind.Base;
return controller;
}
}
Expand Down