private static object OnCoerceContextMenu(DependencyObject sender, object value, CoerceValueCallback originCallback) { var menu = originCallback?.Invoke(sender, value) ?? value; if (menu is ContextMenu contextMenu) { var ribbon = (Ribbon)sender.GetValue(RibbonProperty); ribbon?.ValidateContextMenu(contextMenu); } return(menu); }
public DependencyProperty RegisterProperty <T>( string name, T defaultValue, FrameworkPropertyMetadataOptions flags, PropertyChangedCallback propertyChanged = null, CoerceValueCallback coerceValue = null) { FrameworkPropertyMetadata metadata = new FrameworkPropertyMetadata( defaultValue, flags, (d, e) => propertyChanged?.Invoke((TOwner)d, e), (d, e) => coerceValue?.Invoke(d, e)); return(DependencyProperty.Register(name, typeof(T), typeof(TOwner), metadata)); }