39 lines
1.0 KiB
C#
39 lines
1.0 KiB
C#
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
using WPFluent.Appearance;
|
|||
|
|
using WPFluent.Interop;
|
|||
|
|
|
|||
|
|
using System.Windows.Controls;
|
|||
|
|
|
|||
|
|
namespace WPFluent.Extensions;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Extensions for the <see cref="ContextMenu"/>.
|
|||
|
|
/// </summary>
|
|||
|
|
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;*/
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Tries to apply Mica effect to the <see cref="ContextMenu"/>.
|
|||
|
|
/// </summary>
|
|||
|
|
public static void ApplyMica(this ContextMenu contextMenu) { contextMenu.Opened += ContextMenuOnOpened; }
|
|||
|
|
}
|