using WPFluent.Appearance; using WPFluent.Interop; using System.Windows.Controls; namespace WPFluent.Extensions; /// /// Extensions for the . /// internal static class ContextMenuExtensions { private static void ContextMenuOnOpened(object sender, RoutedEventArgs e) { if(sender is not ContextMenu contextMenu || PresentationSource.FromVisual(contextMenu) is not HwndSource source) { return; } if(ApplicationThemeManager.GetAppTheme() == ApplicationTheme.Dark) { _ = UnsafeNativeMethods.ApplyWindowDarkMode(source.Handle); } // TODO: Needs more work with the Popup service /*if (Background.Apply(source.Handle, BackgroundType.Mica)) contextMenu.Background = Brushes.Transparent;*/ } /// /// Tries to apply Mica effect to the . /// public static void ApplyMica(this ContextMenu contextMenu) { contextMenu.Opened += ContextMenuOnOpened; } }