Search code examples
wpfcontextmenuextend

wpf extend contextmenu of textbox


I am searching for a way to extend the contextmenu of a textbox. I know there are dozens of solutions out there that recreate the contextmenu as a whole, but how on earth can I simply add one custom entry to a existing context menu?

Thanks Klaus


Solution

  •  <TextBox>
            <TextBox.ContextMenu>
                <ContextMenu>
                    <MenuItem Command="ApplicationCommands.Cut" />
                    <MenuItem Command="ApplicationCommands.Copy" />
                    <MenuItem Command="ApplicationCommands.Paste" />
                    <MenuItem Command="ApplicationCommands.SelectAll" />
               //Your own item here
                </ContextMenu>
            </TextBox.ContextMenu>
        </TextBox>
    

    Please not that all command are automatically operation and will work as expected