How to set ContextMenuMy style to MenuItem from code?
item = new MenuItem { Background = HexToColorConverter.GetColorFromHex("#FF222222"), Foreground = HexToColorConverter.GetColorFromHex("#FFCCCCCC"), BorderBrush = HexToColorConverter.GetColorFromHex("#FF222222"), Style = (Style)(this.Resources["ContextMenuMy"])//new Style(), Background, Foreground, BorderBrush work.
Error CS1061 'SpellCheckBehavior "does not contain a definition for" Resources "and could not find the extension method" Resources ", accepting the type" SpellCheckBehavior "as the first argument (it is possible that the using directive or the link to the assembly was omitted).
XAML's ContextMenuMy style is applied to other elements in this way.
<TextBlock.ContextMenu > <ContextMenu Style="{DynamicResource ContextMenuMy}" >
textEditor.ContextMenu.SetResourceReference(Control.StyleProperty, "ContextMenuMy");workstextEditor.ContextMenu.SetResourceReference(Control.StyleProperty, "ContextMenuMy");- codename0082016