Follow these steps to add a context menu to a TextBlock control. The same steps can be followed to add a context menu to any of the controls inheriting FrameworkElement:
- Open the MainWindow.xaml file to modify the application UI.
- Replace the entire Grid block with the following XAML code:
<Grid> <TextBlock Text="Right-click on me to open Context Menu!" Margin="10"> <TextBlock.ContextMenu> <ContextMenu> <MenuItem Header="Menu item 1" /> <MenuItem Header="Menu item 2" InputGestureText="Ctrl + R, Ctrl + G"/> <Separator /> <MenuItem Header="Menu item 3" IsCheckable="True" IsChecked="True" /> </ContextMenu> </TextBlock.ContextMenu> ...