// ReSharper disable once CheckNamespace
namespace Fluent
{
using System;
using System.Windows;
using Fluent.Internal.KnownBoxes;
///
/// Represents additional context menu service
///
public static class ContextMenuService
{
///
/// Attach needed parameters to control
///
public static void Attach(Type type)
{
System.Windows.Controls.ContextMenuService.ShowOnDisabledProperty.OverrideMetadata(type, new FrameworkPropertyMetadata(BooleanBoxes.TrueBox));
FrameworkElement.ContextMenuProperty.OverrideMetadata(type, new FrameworkPropertyMetadata(OnContextMenuChanged, CoerceContextMenu));
}
private static void OnContextMenuChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
d.CoerceValue(FrameworkElement.ContextMenuProperty);
}
///
/// Coerces the ContextMenu for .
///
///
public static object CoerceContextMenu(DependencyObject d, object basevalue)
{
var control = d as IQuickAccessItemProvider;
if (basevalue is null
&& (control is null || control.CanAddToQuickAccessToolBar))
{
return Ribbon.RibbonContextMenu;
}
return basevalue;
}
///
/// Coerce control context menu
///
public static void Coerce(DependencyObject o)
{
o.CoerceValue(FrameworkElement.ContextMenuProperty);
}
}
}